After running a ASP.NET website on IIS 7.5 for the first time on a Windows 7 computer, I was faced with the following error message:
Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
To fix this issue, try changing the (Process Model) Identity of your website's Application Pool to use the NetworkService account (or the less secure LocalSystem account). By default, IIS7 seems to set the Application Pools Identity to 'ApplicationPoolIdentity', instead of NetworkService or LocalSystem.
Here's a step-by-step guide for determining your websites Application Pool, then changing its Process Model Identity in IIS7:
- Open Internet Information Services (IIS) Manger.
- In the Connections sidebar, drill down into Default Web Site and click on your website.
- Now in the Actions sidebar (on right side), click on Advance Settings... In the popup box, under General you will see your Application Pool listed for your website (in my case the app pool is: ASP.NET V4.0).
- Click Cancel... If you choose, you can change the Application Pool here, but for the sake of this example we just wanted to find out what the website's App Pool was.
Now that we know the Application Pool that is configured for your website, we now want to change the app pool's (Process Model) Identity to 'NetworkService', here's how:
- Open Internet Information Services (IIS) Manger.
- In the Connections sidebar, click on Application Pools.
- Now right-click on the Application Pool that your website is using (in this case my site is using the ASP.NET v4.0 application pool), and select Advanced Settings... from the menu.
- In the Advanced Settings pop-up box, locate the Process Model -> Identity section and click on the Application Pool Identity.
- In the Application Pool Identity pop-up box, change the Built-in account to NetworkService (or if you want LocalSystem), then click OK, and click OK again to save your Advanced Settings changes.
After changing the Application Pool's Identity to NetworkService (or LocalSystem) you should now be able to get your ASP.NET site to run successfully on an IIS7 web server.
NOTE: It really is not considered the safest as far as security is concerned to use NetworkService or LocalSystem as the Application Pool. It is actually much better to use a sites application pool such as: MySiteName_AppPool. To do so, you would need to give the username MySiteName_AppPool "Read" and "Write" permissions to any folder on your Website that you will be uploading content or deleting content (such as pictures, media, etc.). Such as C: -> inetpub -> wwwroot -> MySiteName -> "somedirectoryfolder" would need "Read" and "Write" permission for the username MySiteName_AppPool.
To do this, go to C: -> inetpub -> wwwroot -> and right click on your sites folder "MySiteName" -> then click Properties --> then select the Security tab -> click Edit -> then click Add -> Within the "Enter the object names to select, type: "IIS APPPOOL\MySiteName_AppPool" and click OK -> then in the Permissions for box, make sure to Allow Read and Write and/or check all with Full Control then click OK.
In your SQL Server database, you would then create a Login with the UserName: IIS APPPOOL\MySiteName_AppPool and then make the User Mapping for the logins Default Schema "dbo" and make sure the Database role membership has "db_owner" checked.