| Subcribe via RSS

Get NT Authenticated User in ASP.NET

August 12th, 2009 | Comments Off | Posted in ASP.NET, IIS

Sometimes we want to log who is making changes to the system. I’m sure there are some SQL tricks you could do to pick it up when the stored procedure is called, but I’m a programmer instead of a database guy so I opt for the ASP.NET solution. ASP.NET has the HttpContext class which can get at all sorts of interesting underlying processes like items in cache, whether debugging is enabled or even just pulling back the timestamp off the server. For our purposes, we are going to step down into the Current.User.Identity.Name to find out who our user is. Now for this to work we need to have our program setup on IIS as its own application with Security enabled (Windows Basic). This will force the user to login using their NT network credentials. The login will actually look something like DomainName\UserName. More than likely we won’t be interested in what network they were signing in over just who they are. Current.User.Identity.Name gives us that and nothing else. Pretty handy when you’re trying to pin a system screw up on a user.

Tags: , ,

Windows 7 Beta Online: Free Download

May 6th, 2009 | Comments Off | Posted in IIS, Windows 7

Around January, Microsoft put the latest build of Windows 7 release candidate online. It was a free download, and they’d give you an activation code that would expire in 6 months to a year. All this was an effort to recruit developers and tech professionals to assist them in their beta testing efforts. As of February, you could no longer download the software yet you could still get activation codes. Seems a little ass backwards to me, but this is Microsoft we are talking about. This morning Microsoft opened back up download of Windows 7 with their final release candidate. Get Windows 7 RC here.

I managed to get a copy to test out off the torrents a couple months ago, and I have to say I’m impressed. This is coming from a guy that was so fed up with Vista that I rolled back to XP Pro even in the face of numerous headaches and hassles. Here’s what I’ve experienced so far with Windows 7:

? The install was amazingly fast. I do have a fairly new computer, but I’ve never had an install take less than an hour from start to finish. Windows 7 was up-and-running in 30 minutes.

? The computer was ready to use right at startup. All the drivers were installed for everything — graphics, sound even printer. I’ve never in my wildest imagination thought of Windows hooking up the printer, but they did. Very cool and saved lots of time of tracking down device drivers.

? After a month, I haven’t run into any compatibility issues with programs I’m running. Every once in awhile a program will trigger the “this program may not work properly” message like Adobe Acrobat, but it seems to truck along fine.

? The look-and-feel of Windows 7 reminds me a lot of Vista without those backend headaches that consistently plagued Microsoft’s ugly step-child.

? Its incredibly stable for a release candidate. I’ve had it running for the past 3 weeks and just rebooted it because general memory leaks were causing the box to run sluggish. I have yet to see a blue screen, a system crash or anything running haywire.

? It has a nice new features set. If you are a Windows developer, IIS7 is a nice built from the ground update to IIS. I’m still winding my way through the features of IIS7. Many more features to Win7 that I’m just to lazy to get into. A few can be checked out here.

In general, Windows 7 is a great OS. After being happy as a clam on XP, they lost a lot of luster in my eyes after the Vista debacle, but they’ve clearly learned from their mistakes with Windows 7. Now for my obligatory disclaimer on loading Windows 7. If you aren’t tech savvy, just wait until the final build comes out for the public. Release candidates can be buggy and incompatible with certain softwares. If you know what you are doing, load it up and have fun playing in Microsoft’s new sandbox.

Tags: , , ,

Reading Files from a Directory using C#

April 24th, 2009 | Comments Off | Posted in C#, General, HTML, IIS, Programming, VB.NET
So I had a project which I needed to find out what files were being held in a given directory and write those back to the browser. This is very helpful in automating posting of files to a website by your users without you being involved in tedious static html updates. The key here is the System.IO .NET class. We are going to access the DirectoryInfo class so we can iterate through and pull back all file objects contained within. In the code below, the DirectoryInfo looks in the current directory as we’ve defined through Server.MapPath(“.”). We could just have easily directed this through stepping up the directory (i.e. c:\intepub\wwwroot\directoryread\filestoread\). Next, we tell it to grab all the files that end with an .aspx extension which screens out any text or pdf files we may not be interested in. In the FileInfo class, we extract the name of each file to wire up the hyperlink and print this back to the user. I’ve taken it one step further to strip out the hyphens and the .aspx file extension that we print back to the user so the file name “Reading-files-from-a-directory-using-csharp.aspx” becomes “Reading files from a directory using cSharp”. Much cleaner and user friendly. That FileInfo class has lots of cool properties including LastWriteTime, CreationTime, Length (for a full rundown on the FileInfo properties checkout Microsoft’s .NET Framework Developer Center). Tags: , ,

IIS Error – XML Parsing Error: not well-formed

March 2nd, 2009 | Comments Off | Posted in ASP.NET, IIS

This message triggered when trying to pull up a standard ASP.NET page on IIS that I know was working on another computer. This was a basic ASP.NET page, not an XML document. It appeared the extension mappings were off. So I pull up the command prompt, and navigate to the aspnet_iis.exe file (on my machine this was located at c:\Windows\Microsoft.NET\Framework\v2.0.507277). From there I run the following command:

aspnet_iis -i

This is the handy app that registers ASP.NET with IIS. It updates the script mapping of an application with its specific ISAPI extension.

Tags: , ,