Monday, June 21, 2010

Classic ASP Login failed for user 'NT AUTHORITY\IUSR'

Most often I build asp .net applications and connect to a local development database using windows authentication. I tried to do the same thing (connect using windows authentication) with a classic asp application I'm working on converting to .net, and got this error:
Login failed for user 'NT AUTHORITY\IUSR'

To remedy the issue I did the following:
1. Open Microsoft SQL Server Management Studio
2. On Registered Servers expand nodes to find database server
3. Right-click on database server > Object Explorer
4. Expand 'Security' node
5. Right-click on 'Logins' > 'New Logins...'
6. Login name: 'NT AUTHORITY\IUSR'
7. Click 'OK'
8. Expand 'Databases' node > 'Your_DB_Name' node > Security
9. Right-click 'Users' > 'New user..."
10. User name: 'Whatever_you_want'
11. Login name: NT AUTHORITY\IUSR
12. In the 'Database role membership', check 'db_datareader' and 'db_datawriter'
13. Click 'OK'

That was it - the classic application was able to connect.

I could have created a new user and connected using SQL Server Authentication mode (I actually tried this first, but then realized the server security settings were set to 'Windows Authentication mode' not 'SQL Server and Windows Authentication mode'), but this allowed me to keep my current server security setting of 'Windows Authentication mode' and keep my connection strings consistent between my classic asp and asp .net applications.

IIS 7 and Classic ASP

Since Classic ASP is over a decade old, Microsoft seems to want to forget it ever existed by making it difficult to deploy classic asp apps. I was reminded of this again in a recent project where I am converting an existing classic asp application to a .net app.

I first wanted to set up the classic asp application on my own (windows 7 64bit) machine so I could dissect it and use some of the existing logic. After adding a new application in IIS and trying to browse to the default page, I was getting a 404 error. After googling a bit, I discovered that there must be some special configuration for classic asp apps... and then I found a link that explained that Classic ASP Not Installed by Default on IIS 7.0. That was nice of them - first issue solved.

Second issue: I was then getting this vague error:
An error occurred on the server when processing the URL. Please contact the system administrator.

Thanks! I am the administrator :(

After some digging, I found out that error messages are not sent to the browser by default for asp pages in IIS7 in case sensitive information is displayed. I followed the instructions and now I can see the errors.

Now I can get to work on the conversion.