Wednesday, February 2, 2011 by Nate Bross
Someone asked on Stack Overflow:
I have a function for our intranet application which will log user navigation and activity. I want to track users and need to run this function on every single page. We cant use any Google Analytics or other tools as this is intranet app and people wont have access online.
What would be the best way to perform this?
Should be create BasePage or put the code into the Masterpages? Other options?
Basically we need to check if user has session and then track his activity, both functions should be run on every single page.
edit
I forgot to mention that we need to view logs and activity online using our system. We will track user, their actions, activity and possible problems.
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
Both options you mention should work, if you’re doing new dev, I might go for the inherited page route — if you’re tacking this on to an existing system, I might just drop it in the master page and be done with it.
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, February 1, 2011 by Nate Bross
Someone asked on Stack Overflow:
I am having some difficulty with doing an automated login for users in my desktop Active Directory application. I may be trying to do an SSO, but I am under the impression that is only for web applications.
The code I have, is this:
PrincipalContext theContext = new PrincipalContext(ContextType.Domain);
if (theContext.ValidateCredentials(null, null))
Console.WriteLine("Credentials have been validated. Tell your friends.");
else
Console.WriteLine("Invalid credentials");
UserPrincipal user = new UserPrincipal(theContext, "uatu", "Passw0rd", true);
user.Save();
The PrincipalContext is being created without error, and I am validating the credentials. I assumed this would validate me as the user that logged in to the computer, which is under the Active Directory domain. And I can find users and groups. But as soon as I call user.Save() I get the error “Access is denied.” Am I actually getting into Active Directory as a guest user?
If I set the user name and password in ValidateCredentials, it doesn’t help.
PrincipalContext theContext = new PrincipalContext(ContextType.Domain);
if (theContext.ValidateCredentials("<username>", "<password", ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing))
Console.WriteLine("Credentials have been validated. Tell your friends.");
else
Console.WriteLine("Invalid credentials");
UserPrincipal user = new UserPrincipal(theContext, "uatu", "Passw0rd", true);
user.Save();
That code still fails on user.Save(). If I explicitly set the username and password to match myself as the logged in user in the PrincipalContext constructor, then I get success.
PrinicipalContext theContext = new PrincipalContext(ContextType.Domain,"<address>", "<domain context>", "<username>", "<password>");
UserPrincipal user = new UserPrincipal(theContext, "uatu", "Passw0rd", true);
user.Save();
That code succeeds. But I would rather not have the user log in to my application after they have logged into their computer with the exact same credentials.
I have been hearing a bit about “Affiliate Application”, so I’m wondering if I have to let Active Directory know that it can trust my application. I am still hazy on the details through, and don’t know if that is the wrong direction.
Does anyone have an idea as to what I should be doing?
I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:
If you are trying to modify UserPrincipals, you have a couple options:
- User is already authenticated to windows as a user with permission to edit active directory:
- Use the Constructor for
PrincipalContext which doesn’t take username/password
- This will run the context as the currently logged in user
- Run query,
var usr = UserPrincipal.FindByIdentity(ctx, "bob@domain.local");
- Perform manipulations on
usr object
- Call
usr.Save(); on the returned user from the query.
- User is authenticated to windows, but you must “impersonate” a user with AD permission
- Use the Constructor for
PrincipalContext which takes username/password
- This will run the context as the credentials you passed in
- Run query,
var usr = UserPrincipal.FindByIdentity(ctx, "bob@domain.local");
- Perform manipulations on
usr object
- Call
usr.Save(); on the returned user from the query.
Based on your explanation above, I’m presuming you need option #1. ValidateCredentials(); is only used to validate credentials, it returns a true/false if the credentials you’ve given it are valid. Calling it has no lasting affect, it only validates. If you need to impersonate a user, you need to use the PrincipalContext constructor which takes credentials.
Notable comments
Nate (0 upvotes): You may need to delegate if the users doing modifications are not domain admins.
Nate (0 upvotes): You may need to “Delegate Control” of a the Organizational Unit that contains the users. When you delegate, you can pick a single user or a security group. Right click on the OU and choose “Delegate Control.”
Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.
Wednesday, January 26, 2011 by Nate Bross
Someone asked on Game Development:
if I want to build a game for web, facebook, and iphone, do I need to build 3 completely different versions? I know there is a new company that is “build once, launch anywhere,” but I’m asking about current best/practice and methodology in doing this.
I posted the following answer, which was chosen as the accepted answer and received 1 upvote:
This really depends what type of game that you are making.
If your game is a simple text based game, then you can build the same interface in HTML and use different CSS to make it look good based on where the game is being accessed from.
More realistically, your game is highly interactive, and it would be best to build the web/facebook version in Flash/Silverlight or another browser plugin. Then port it to iPhone in Objective-C. (Or, if you’re more proficient in Objective-C start there and port to web/facebook.)
The main issue that you’ll probably run into is that on iPhone the input scheme will be different which could impact gameplay.
The bottom line, is that you will need to, at a minimum, build a different Rendering and Input scheme for each platform you wish to deploy to. Facebook, is really just a normal web deployment, inside the facebook site, so the design would be the same for facebook or any other web game.
edit
A few things I’d like to point out, based on your comments. First, HTML5 is probably NOT a good place to start, it has poor browser support (thought getting better), I’d stick with HTML4 and/or XHTML 1.1 and CSS2, these will work in almost all modern browsers; however, if you require any animation, I’d recommend using Flash or Sliverlight to build the game, and use their associated ability to call web services to save state to a server. Second, HTML is just the presentation, if you don’t go the plugin route, you would likely need PHP or ASP.NET on the server to manage your game state and persist it to a database.
Notable comments
Nate (0 upvotes): Yes, I would think so. It depends how you build it. It will be most easy if you follow the principles of csszengarden.com
Nate (0 upvotes): For a go-fish type of game, you could probably use HTML and javascript, which you could adapt to work on all of your listed platforms, with minimal changes.
Originally posted on Game Development — 1 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, January 24, 2011 by Nate Bross
Someone asked on Stack Overflow:
I have a list of items of type Country and I’m trying to find the index of and specific Country on the list but the IndexOf() method always returns -1.
The Country object look like this:
public class Country
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
}
Then when I try to use the IndexOf() method I do the next:
var newcountry = new Country
{
CountryCode = "VE",
CountryName = "VENEZUELA"
};
var countries = ListBoxCountries.Items.Cast<Country>().ToList();
if (countries.IndexOf(newcountry) == -1)
countries.Add(newcountry);
Lets assume I have an already filled list with with the countries and “Venezuela” is on the list, the IndexOf() method never find the country.
EDIT:
So I got a little help from ReSharper here and he made this once I told him to override the Equals() method:
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (Country)) return false;
return Equals((Country) obj);
}
public bool Equals(Country other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other.CountryCode, CountryCode) && Equals(other.CountryName, CountryName);
}
public override int GetHashCode()
{
unchecked
{
return ((CountryCode != null ? CountryCode.GetHashCode() : 0)*397) ^ (CountryName != null ? CountryName.GetHashCode() : 0);
}
}
And here comes another question: It’s ok to do all this just to compare two objects?
I posted the following answer, which was chosen as the accepted answer and received 1 upvote:
I suspect this is due to a reference issue. You’ll need to override the Equals(); method in your Country class to check.
I’d use code like this:
public bool Equals(Country other)
{
return this.CountryName.Equals(other.CountryName);
}
Notable comments
Nate (0 upvotes): You may also need to implement GetHashCode() but I don’t see why Equals() is insufficient.
Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.
Friday, January 21, 2011 by Nate Bross
Someone asked on Game Development:
I am wondering how to creat a mini-game like “Diner Dash” or like “Big Fish Games”. I want my game to be 2d, but it looks like 3d: see this image. http://www.topxgames.com/bigfish/diner-dash-flo-through-time/screen1.jpg Also, if you know some good game-engine to create games like those then thanks a lot in advance.
I posted the following answer, which was chosen as the accepted answer and received 7 upvotes:
I’m assuming that you are confusing the term “mini-game” with “casual game.” I’m going to attempt to answer you with the assumption that you are talking about creating a casual game, which is still a very broad question, but I’ll try to give it a stab from a high-level; however, if you really do have a full game and are just looking to add mini-games to it, I don’t know what I can offer to guide you there.
Some key concepts for casual games, are (all my opinion):
- Quick to play, that is to say your game should have gameplay that is very simple to pick up and just play. You shouldn’t have a “tutorial mode” or any of that, it should be so simple anyone can figure it out.
- By extension of quick to play, most popular casual games have gameplay that is on the shorter end of the spectrum, 30-90 seconds is common.
- Progress after a gameplay period should be saved.
I can only speak for myself, but XNA has a very low cost of entry, the learning curve is small if you already are familiar with C++ and/or Java. It also lets you deploy your game to Xbox, Windows Phone, and PC.
As @Spooks said, 2D games that appear to be 3D are frequently called 2.5D or pseudo-3D. And is typically done with 2D sprites that appear to be 3D.
Originally posted on Game Development — 7 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, January 20, 2011 by Nate Bross
I asked this on Stack Overflow:
I’m trying to write a PowerShell script to build a list of files, from several directories. After all directories have been added to the main list, I’d like to do the same processing on all files.
This is what I have:
$items = New-Object Collections.Generic.List[IO.FileInfo]
$loc1 = @(Get-ChildItem -Path "\\server\C$\Program Files (x86)\Data1\" -Recurse)
$loc2 = @(Get-ChildItem -Path "\\server\C$\Web\DataStorage\" -Recurse)
$items.Add($loc1) # This line fails (the next also fails)
$items.Add($loc2)
# Processing code is here
which fails with this error:
Cannot convert argument “0”, with value: “System.Object[]”, for “Add” to type “System.IO.FileInfo”: “Cannot convert the “System.Object[]” va lue of type “System.Object[]” to type “System.IO.FileInfo”.”
I am mostly interested in what is the correct approach for this type of situation. I realize that my code is a very C way of doing it — if there is a more PowerShell way to acomplish the same task, I’m all for it. The key, is that the number of $loc#'s may change over time, so adding and removing one or two should be easy in the resulting code.
Keith Hill answered (40 upvotes):
Not sure you need a generic list here. You can just use a PowerShell array e.g.:
$items = @(Get-ChildItem '\\server\C$\Program Files (x86)\Data1\' -r)
$items += @(Get-ChildItem '\\server\C$\Web\DataStorage\' -r)
PowerShell arrays can be concatenated using +=.
Originally posted on Stack Overflow — 25 upvotes. Licensed under CC BY-SA.
Wednesday, January 12, 2011 by Nate Bross
Someone asked on Stack Overflow:
I am trying to figure out how to get the parameters that are passed in the URL from a jQuery plugin that I am using. Basically, I’m sending a POST ajax request to my web service and trying to use the URL parameters, but they are always returned as nothing. I’m assuming this has to do with the fact that I’m in a POST.
Can anyone please provide some insight for me on how to accomplish this?
I posted the following answer, which was chosen as the accepted answer:
If you’re using asp.net WebForms, I recommend using the ScriptManager to generate a javascript proxy to your web-service, and then use that javascript proxy instead of manually doing an ajax call. Here’s a quick tutorial/walk-through on using ScriptManager with web services: http://msdn.microsoft.com/en-us/magazine/cc163354.aspx
Something roughly like this:
// in html you have this
<script src="WebService.asmx/jsdebug" type="text/javascript"></script>
// csharp web-service like this
[WebMethod]
public int Add(int a, int b) { return a + b; }
// further javascript to call it
function CallAdd()
{
// method will return immediately
// processing done asynchronously
WebService.Add(0,6, OnMethodSucceeded, OnMethodFailed);
}
This should eliminate the need to post parameters via query-string, which is typically not supported in a soap environment, as the service expects a well-formed soap message.
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, December 28, 2010 by Nate Bross
Someone asked on Stack Overflow:
Possible Duplicate:
Storing Images in DB - Yea or Nay?
Is it faster and more reliable to store images in the file system or should I store them in a database?
Let’s say the images will be no larger than 200 MB. The objective is fast, reliable access.
In general, how do people decide between storing files (e.g., images, PDFs) in the file system or in the database?
I posted the following answer, which was chosen as the accepted answer and received 15 upvotes:
Personal opinion: I ALWAYS store images on the file system, and only store a filepath in the database. In many situations, databases are stored on fast (read: expensive storage, 15k RPM or SSD drives) storage. Images or other files, typically can be stored on slower (read: cheaper, larger drives, 7.2k RPM drives) storage.
I find this to be the best, since it allows for the database to remain small in size. In general, databases store “data” well. They can search and retrieve small bits of data fast. File Systems store “files” well, they are optimized to find and retrieve larger bits of data fast.
Obviously there are tradeoffs to both approaches, and there isn’t going to be a one-size fits all; however, there may be some use cases where storing images in the database is a good thing, if they are all quite small, and you don’t anticipate very many of them, and your database is on the same storage medium as your file share, then it probably makes sense to drop the images directly into the database.
As a side note, SQL Server 2008R2 has a FileStream field type, which can provide the best of both worlds, I have not used it yet, so I can’t speak to how well it works.
Originally posted on Stack Overflow — 15 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, December 28, 2010 by Nate Bross
Someone asked on Stack Overflow:
I have a Solution which contains an ASP.NET Web Application project. Web Application project types can only target the full .NET Framework 4, and Visual Studio won’t let you select the Client Profile.
However, my Class Library projects in that same solution allow me to target the .NET Framework 4 Client Profile.
So, should I mix targeting the Client Profile and the full framework in the same solution? Or just target the full framework for every project type in a Solution containing a Web Application project? Or does it not matter either way?
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
If you plan to reuse the Class Library in a WPF or WinForms app, then Client Profile is a good choice, since you are likely going to be able to set your WPF or WinForms app to use Client Profile as well. Even if your WPF or WinForms app ends up requiring the full framework, Client Profile is a subset of the full framework so it will still work just fine.
If your reuse plans on the Class Library are WebApp only or your only using a Class Library to help segment code, then the target framework is really not important.
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, December 27, 2010 by Nate Bross
Someone asked on Stack Overflow:
I’m looking for a .NET component which aid me the introduction of VNC communication compatibility to an application.
The application already installs necessary Windows hook, so I’m interested only on a library which able me to communicate with VNC clients without re-implementing the VNC protocol.
Is there such library?
If it is possible, I’d like to have a closed license compatible components (i.e. LGPL).
I posted the following answer, which was chosen as the accepted answer:
VNCSharp is a client library. I’m unsure of its full abilities, as VNC allows both “client” and “server” to act as each other; but it should be a good starting point. That said, as far as I know, it may be the only .NET starting point as its the only .NET VNC component I’ve ever been able to locate.
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.