
Using a Different Process Identity while Running an ASP.NET Unit Test
When you are testing ASP.NET code, the test code runs in either the IIS process or in an ASP.NET Development Server process. If your ASP.NET unit test is running in the IIS process, you can choose to have the ASP.NET process run as a non-default user, that is, with a different process identity, for security purposes.
For example, if the ASP.NET Web site must access resources on the computer such as folders, files, or a database, you can choose to run it so that its permissions on these resources are exactly enough, no more.
Note: |
|---|
The default identity depends on the version of IIS. In Windows Server 2003, for example, the default identity of the ASP.NET process, w3wp.exe, is "NETWORK SERVICE."
|
Unit test execution can fail in this situation. For example, the ASP.NET process that is running as a non-default user might have restricted permissions, but still might try to generate temporary files to the %WINDIR%\Temp folder. This would fail if the default permissions on %WINDIR%\Temp do not allow the process sufficient access to generate those files. In this case, for unit test execution to succeed, you would have to grant the process higher permissions on the %WINDIR%\Temp folder.
Unit test execution can also fail if the service account does not have access to the deployment root folder. If this happens, Visual Studio displays a dialog box that explains the error and lets you get past it by clicking OK.