ASP.NET Support Voice column
Troubleshooting common permissions and security-related issues in Microsoft ASP.NETTo customize this column to your needs, we want to invite you to submit your ideas about topics that interest you and issues that you want to see addressed in future Knowledge Base articles and Support Voice columns. You can submit your ideas and feedback using the Ask For It form. There's also a link to the form at the bottom of this column.
The focus of this column will not be to explain ASP.NET security, but to outline a few troubleshooting techniques and tips that will help you isolate and resolve some of the common permissions and security scenarios that we see here at PSS. Permissions and security-related issues in ASP.NET are very well documented. In fact, there will be a good number of people who might have run into the same issue prior to you. So, the intent is for this column to be a good place to find relevant and exhaustive information on ASP.NET security. There is no better feeling than fixing the issue yourself.
Useful toolsBefore you attempt to fix anything that is broken, you need to familiarize yourself with a few tools which will help you narrow down the issue. In our case, we would be interested in tools like FileMon, RegMon, and Security Auditing. For more information about FileMon, visit the following Microsoft Web site:
Drill down to isolate the problem
- Has the application ever worked? If yes, then what changed that could have made the application break? It's possible that software updates or security updates were applied on the server. A code rollout also could have caused the issue.
- Do simple .html and .asp pages serve from IIS?
- Was the application migrated to a different version of IIS?
- Do other ASP.NET applications on the server fail with the same error? Is this the only application that fails?
- Does the issue occur for all users or for only specific users?
- Is the issue reproducible while browsing locally on the Web server, or is it reproducible for only a few clients?
- If you are using impersonation, then does the impersonated user have the necessary access to the resource?
What is the exact error message?The first question we ask customers is, "What is the exact error message?" If you have a clear description of the error message thrown by the Microsoft .NET Framework, you can skip this section. If your application masks the actual error message and gives you a friendly error message instead, such as, "An unexpected error has occurred. Please contact the website administrator for details," it's not of much use to anyone. Here are a few steps which will help you get the actual error message.
- Locate and open the Web.config file in the application directory and change customErrors to mode="Off". Save the file, and reproduce the problem.
- It still might not be possible to see the actual error message after following the above step because of custom event/error handling done by the application developer. You can try to locate the Application_Errorevent in the Global.asax file and comment out any code that uses the
Server.Transfer("Errors.aspx") function to go to a custom error page.
void Application_Error(object sender, EventArgs e)
// Code that runs when an unhandled error occurs
Tip You can contact your developer to find out how to see the actual error message. It's possible that your developer may be logging it to a file or getting e-mail notifications. Always remember to make a backup of any file that you are going to change. With a backup available, you can always roll back any changes.
Issue occurs because of missing permissions on a local resource that the ASP.NET application tries to accessIf you are unable to get a clear description of the problem because of a custom error message, run FileMon and reproduce the problem. Stop and save the capture as FileMon.xls and open the file in Microsoft Excel. On the Data menu, click Filter, and then click AutoFilter to use the filtering capabilities of Excel. Now select the drop-down list in column F and look for "ACCESS DENIED" errors.
A sample FileMon output is shown below.
10381 1:01:11 PM w3wp.exe:2320 OPENAs you can see from the filtered results, we have narrowed down the cause of the problem. FileMon shows that the NT AUTHORITY\NETWORK SERVICE account is missing NTFS permissions on the C:\Winnt\Microsoft.net\Framework\v1.1.4322\Temporary ASP.NET Files folder. This should be straight forward to fix.
Files\sessiontest\8832e585\275ec327\global.asax.xml ACCESS DENIED NT
For more information about using FileMon to troubleshoot ASP.NET, click the following article number to view the article in the Microsoft Knowledge Base:
userName to "SYSTEM" in the process model section of the machine.config file and in IIS 6.0 you would change the IIS AppPool identity to "Local System" to see if the application works.
Note This should not be used as a solution, but only as a troubleshooting step.
Most people would tend to reinstall the Microsoft .NET Framework or even go to the extent of reinstalling the operating system. This is not a recommended troubleshooting step and does not guarantee that the issue will not reoccur. I will provide one such example. Intermittent issues are often hard to isolate and troubleshoot. In this scenario the customer's application would work fine for a few hours, and then all of a sudden it would fail with the error below. The customer had already tried reinstalling the .NET Framework as well as the operating system. This seemed to fix the problem for a few days, but then it reappeared.
Running FileMon did not show any ACCESS DENIED errors. All the necessary permissions for the ASPNET account were in place. The only way to recover from the problem is to reboot the box. Even an IIS reset would not help. You are thinking "Ah, Microsoft Software always needs a reboot to recover?" Well, you are wrong!
The key here is to look closely at the error message. The error clearly says "cannot open a file for writing," and not the usual ACCESS DENIED error, so I am thinking that it's some other process that is holding a lock on a file or folder and not allowing ASP.NET to write to it. It makes sense that a reboot was killing the other process and the ASP.NET application starts working again until the rogue process locks the file again. The logical thing to do would be to turn off all antivirus programs, third-party spyware, or any other file monitoring software that runs on the server. I do not want to point out any specific third-party software. But, in general, antivirus software is known to cause a lot of grief for IIS and ASP.NET applications. Another known issue caused by antivirus software is session loss due to AppDomain recycles when the Bin folder or the .config files are touched.
Tip The easiest way to turn off third-party services is to:
- Click Start, click Run, and then type msconfig.
- Select Services and check Hide All Microsoft Services.
- Click Disable All to stop the third-party services.
- Click Start, click Run, and then type iisresetto reload the CLR into the worker process.
Note If the same error is reproducible 100 percent of the time, your antivirus software may not be the cause. There can be other causes for this error. Try creating a simple ASP.NET test application to isolate whether the same error occurs for a Test.aspx page. If it does, then verify that the required Access Control Lists (ACLs) are all in place for ASP.NET.
See ASP.NET Required Access Control Lists (ACLs):
Tip The %SystemRoot%\Assembly folder is the global assembly cache. You cannot directly use Windows Explorer to edit ACLs for this folder. Instead, use a command prompt and run the following command:
Issue occurs because of missing permissions on a remote resource that the ASP.NET application is trying to accessWhen your ASP.NET application is accessing a remote resource like Microsoft SQL Server or a Universal Naming Convention (UNC) share, there are many things that can go wrong. Also, many things may be incorrectly set up on the remote resource. You'll need to troubleshoot those issues in order to get the resource working.For more information, click the following article number to view the article in the Microsoft Knowledge Base:
- On the remote server, create a folder called Test. On the Sharing and Security tabs of the Test folder, add your domain/account, and also the process account that is used by your ASP.NET application, and give them both Full Control.
Note Please see891031 for techniques or workarounds to access remote resources from ASP.NET.
- On the IIS server, log in with your domain/account, click Start, click Run, and then type the UNC share path of the remote server:\\RemoteServerName\TestIf you are unable to get to this folder, then contact your Network Administrator to fix this issue. Only then can your ASP.NET application access the share.
- Create a file called CreateUNCFile.aspx with the code below and save the file in your application directory.
<%@ Page Language="vb" %>
<%@ Import Namespace="System.IO" %>
<title>Writing to a Text File</title>
Sub WriteToFile(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim fp As StreamWriter
fp = File.CreateText("\\<RemoteServerName>\Test\" & "test.txt")
lblStatus.Text = "The File Successfully created! Your ASP.NET process is able to access this remote share"
<body style="font: 10pt verdana">
<h3 align="center">Creating a Text File in ASP.NET</h3>
<form id="Form1" method="post" runat="server">
Type your text:
<asp:TextBox ID="txtMyFile" TextMode="MultiLine" Rows="10" Columns="60" Runat="server" /><br>
<asp:button ID="btnSubmit" Text="Create File" OnClick="WriteToFile" Runat="server" />
<asp:Label ID="lblStatus" Font-Bold="True" ForeColor="#ff0000" Runat="server" />
- Make sure that you modify <RemoteServerName> in the following line of codeso that it reflects the name of your remote server.
fp = File.CreateText("\\<RemoteServerName>\Test\" &"test.txt")
- Open Windows Internet Explorer and browse to http://IISServerName/AppName/CreateUNCFile.aspx from a client computer other than the IIS server.
- If the Test.txt file creates successfully, then your ASP.NET application can authenticate to the remote resource.
- If file creation fails from an Internet Explorer client browser but works if you browse to the same page from the IIS server itself, then it's likely that you are running into a "Double Hop" scenario. If you are using custom built Web Parts to access remote resources that require user authentication and authorization, you will probably run into the "Double Hop" problem. In order to access your remote resource, you may need to supply the end user's credentials to the resource so that the output from the resource is limited to the data that the end user has permission to access.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
Tip If you can connect to the remote UNC share but you can not connect to the remote server that is running SQL Server from the ASP.NET application, then you might have to check or set the Service Principal Names (SPNs) for SQL Server. Try enabling only Basic Authentication for your application in IIS and see if you are able to connect to the remote server that is running SQL Server.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
Code Access Security (CAS) related issueError messages in ASP.NET are detailed and, more often than not, tell you exactly what the problem is. In some cases, FileMon or RegMon may not capture anything useful. Let's take a look at one such scenario.
ScenarioWhile trying to browse an ASP.NET application, it fails with a generic error such as the following infamous error:
Event Source: ASP.NET 1.1.4322.0
Event Category: None
Event ID: 1088
Time: 10:54:04 PM
Failed to execute request because the App-Domain could not be created. Error: 0x8013150a
Level attribute, and then adds the class to the permission set for the application domain. You will see the above error if the trust levels are incorrectly configured or modified. For more information, see "ASP.NET Trust Levels and Policy Files" at the following MSDN Web site: Tip in the "Issue occurs because of missing permissions on a local resource that the ASP.NET application tries to access" section, but do not get disheartened if the application does not work with an Administrator or SYSTEM account. You need to check to see if the issue can be caused by Code Access Security. This can easily be done by turning off Code Access Security using the Caspol.exe utility.
Microsoft (R) .NET Framework CasPol 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
In this scenario, the Permission Set for the My_Computer_Zone code group was set to Nothing. Changing it to Full Trust resolved the issue
Note To access the My_Computer_Zone code group, follow these steps:
- In Control Panel, double-click Administrative tools.
- Double-click Microsoft .NET Framework VersionNumber Configuration.
- Double-click Runtime Security Policy.
- Double-click Machine.
- Double-click Code Groups.
- Double-click All_Code.
- Double-click My_Computer_Zone.
For more information, see ASP.NET Code Access Security:
There are numerous other causes for the "Server Application Unavailable" error message. The event log is your best bet to get more details on the cause of your issue.
IIS-related errorsThe IIS logs are very useful in cases of IIS authentication-related errors. A common scenario is when the user would typically see the following:
MyDomain\UserID_91 184.108.40.206 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727;+InfoPath.1) 401 3 5
This indicates missing NTFS permissions on a file or folder. This error may occur even if the permissions are correct for the file that you are trying to access, but the default permissions and user rights may be missing on other SYSTEM and IIS folders. For example, you may see this error if the IUSR_ComputerName account does not have access to the C:\Winnt\System32\Inetsrv directory.For more information about IIS status codes, click the following article number to view the article in the Microsoft Knowledge Base:
WebSiteName tab, and under Active log format, click Properties to see the Log file directory and name.
The other thing of interest here is the status code 5. You can use the net helpmsg command to get more info on this status code:
ResourcesFor more information, click the following article number to view the article in the Microsoft Knowledge Base:
ASP.NET identity matrix
Previous ASP.NET Support Voice columns
Ask For It form to submit ideas on topics that you want to see addressed in future columns or in the Knowledge Base.