SharePoint Server 2010: Problem getting detailed error messages - asp.net

I'm pretty new to SharePoint and IIS, but I haven't been able to find an answer to this one. I'm deploying a custom ASPX with code-behind to my SharePoint server and need a detailed stack trace to see where my problems are.
This involves modifying the web.config file and setting three attributes of certain tags: <SafeMode CallStack="true" AllowPageLevelTrace="true" /> and <CustomErrors mode="Off" />. There are lots of different web.config files, but my error messages change when I modify a certain one, indicating that I chose the right file to edit.
Error message
The problem, however, is that when I do change these tags, I only get an error message telling me the stack trace cannot be displayed remotely, even if I try to display the page on the server itself. The error message basically tells me that in order to get the complete stack trace, I have to do what I just did: Set CustomErrors mode="Off".

I have had this happen before, but only with certain types of errors (HttpModules).
Try checking the windows event log for a more detailed message. It should be there.
Also try restarting IIS/server to make sure its clean/all services are started.

Related

No line numbers in ASP.NET server errors

I'm using Visual Studio 2010 and C# ASP.NET. When I run my project using F5 key, it launches the ASP.NET Development Server, and that's the server I'm using for my work, not IIS.
Problem is, when I get a "Server error in / application" unhandled exception error, the error page has no line numbers, nor source file name. Just an error description and stack trace. For example:
Server Error in '/' Application.
DataField must be specified. [or whatever error message]
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.InvalidOperationException: DataField must be specified.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[etc]
I am compiling in Debug mode. My PDB is being generated in my project's BIN directory. In my project properties, under Web, NTLM authentication is turned off. In my web.config I have the following:
<authentication mode="Forms">
[...]
<customErrors mode="Off"/>
[...]
<compilation debug="true" targetFramework="4.0">.
Also in my project properties, under Build, the Debug configuration is active, and the DEBUG and TRACE constant checkboxes are turned on. Under Advanced, the Internal Compiler Error Reporting is set True, and Debug Info is set to Full.
The user account I am running under has "Debug Programs" privilege enabled in its group's security policy.
I have researched this question here on Stack Overflow and elsewhere, but I can't seem to find a straight answer that fits my situation. One answer I found involved removing a setting "impersonate=true" from web.config, which apparently applies to IIS, but I'm not using IIS, nor do I have this in my config file. I'm using the built-in ASP.NET Development Server which comes with VS 2010, instead of IIS. Another answer said to set up a symbol server, and set the _NT_SYMBOL_PATH env variable, but I don't know if this applies to what I'm doing.
This is really confusing because I'm using default settings and configuration for everything, and it seems like this would be a common problem most developers would encounter. Unless everyone else is using Publish and doing their development via IIS. Incidentally I haven't tried with IIS to see if I get line numbers, yet. But I want to use the built-in ASP.NET Development Server -- I would expect it to show full debug/trace details for exceptions by default, and maybe even integrate with VS 2010 to break on exceptions and let me step through code. But maybe I'm asking for too much. Anyone?
(If you answer with a suggested solution, please first read the details of my settings above, so you can see whether I already have the setting you're suggesting.)
Followup: I tried with IIS and I get line numbers. But this doesn't solve the issue because I want to use the lightweight Development Server instead.
So, I figured out that line numbers were showing up fine when a .CS source file threw an exception, but not when an exception occurred in an .ASPX source file. For the .ASPX itself, the line number and source code excerpt were not appearing at all, whether in IIS or Development Server. (This is not exactly how I had described the issue originally in my question, above, so this clarifies things a bit.) One of my colleagues said this is just the normal behavior, there's no way around it. He implied that you will have to guess which line the exception is on in your ASPX page.
However, after more research, I found a way! I can get the line numbers when an .ASPX file causes an exception. But I still don't understand why this isn't any easier to set up! Like maybe an option at the page or project level, instead of requiring a block of code to be added.
The following code must be in each page's ASPX.CS itself, not in its Master Page, nor in any parent class derived from Page class (which the page may inherit from). This is because if the other classes' Page_Error handlers are called instead, then the call stack is affected, and the most recent entry doesn't pertain to the error. (I was looking into a solution for this too by traversing the call stack. It appears to be possible, but I ran out of time and gave up for now.)
public void Page_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
StackTrace st = new StackTrace(new StackFrame(true));
StackFrame sf = st.GetFrame(0);
Response.Write("File Name: " + sf.GetFileName().ToString() + "<br>");
Response.Write("Method Name: " + sf.GetMethod().Name.ToString() + "<br>");
Response.Write("Error Line Number: " + (sf.GetFileLineNumber() - 1) + "<br>"); // line numbers are offset by 1 for some reason
Response.Write("Error Column Number: " + sf.GetFileColumnNumber().ToString() + "<br>");
Server.ClearError();
}

Display specific error message on custom error page

I know it's possible in asp.net to create a custom error page in a web app, by putting the following line in the web.config:
<customErrors mode="RemoteOnly" defaultRedirect="frmErrorPage.aspx" />
I have had to do this for my web app, since it is clearly much tidier than letting the program bomb out with it's ugly default error page. My custom error page just has the customer's logo and a brief message saying "Error has occurred. Please return to homepage"
The trouble now is that I have no way of knowing what caused the error, when a customer reports it.
Is there a way to make the actual error message appear on this custom error page too?
You should be using logging to know when/where/what errors occured. The POINT of the custom error page is to not allow the end user to see why it messed up because obviously that could be a security risk. Look into using ELMAH. It automatically creates a nice web gui for any uncaught exceptions. And you can also create logs when you catch the errors yourself.
If you do chose to use ELMAH, I would also strongly recommend installing it with the NuGet package manager

ASP.NET Custom Errors vs. Compilation debug="false" and security

I keep reading that an ASP.NET based web site should have custom errors enabled in the web.config because exceptions will show a stack trace.
I may have a faulty memory (currently don't have access to an ASP.NET website under development), but I thought as long as Compilation debug="false" in the web.config file, then the stack trace will not be displayed.
Is my understanding correct about the debug flag and display of the stack trace? If so, then even if custom errors are not enabled, then won't the only message displayed to remote users for an exception be a the non-descriptive message:
"The page cannot be displayed because an internal server error has occurred."
If so then wouldn't it be OK, from a security perspective, to not display a custom error page for the exception?
No, a stack trace will still be shown even if the debug flag is off, but it will not have line numbers for each call in the stack.
The non-descriptive message is what the browser usually shows instead of the actual error message from the server, unless you change the configuration. Anyone wanting to expose information by causing error messages would know how to do this.
Displaying the stack trace isn't a security risk in itself, but it does expose some information that could potentially make it easier to hack the site. A hacker might for example get a clue as to what's done to sanitase the input and find a way around it.
Custom error messages should almost always be prefered over the default error thrown. It gracefully sends your user to a location where they can keep browsing your site without having to go back and try again.
Turning DEBUGGING off in your web.Config is VERY important and goes beyond just not showing the line numbers and stack trace... it also tells the compiler to build in release mode which optimizes performance dramatically. As soon as your app goes to production, all debugging should be disabled.

Detailed 500 error message, ASP + IIS 7.5

IIS 7.5 , 2008rc2, classic asp, 500 error msg:
The page cannot be displayed because an internal server error has occurred.
I need to know how to configure IIS to get a more detailed error.
I've tried setting to true all of debugging options in the ASP configuration.
But that didn't work. Can anyone help me?
I have come to the same problem and fixed the same way as Alex K.
So if "Send Errors To Browser" is not working set also this:
Error Pages -> 500 -> Edit Feature Settings -> "Detailed Errors"
Also note that if the content of the error page sent back is quite short and you're using IE, IE will happily ignore the useful content sent back by the server and show you its own generic error page instead. You can turn this off in IE's options, or use a different browser.
If you're on a remote server you can configure your web.config file like so:
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
Double click "ASP" in the site's Home screen in IIS admin, expand "Debugging Properties", enable "Send errors to browser", and click "Apply".
Under "Error Pages" on the home screen select "500", then "Edit feature settings" and select "Detailed Errors".
Note that the same steps apply for IIS 8.0 (Windows Server 2012).
After trying Vaclav's and Alex's answer, I still had to disable "Show friendly HTTP error messages" in IE
TLDR:First determine where in the pipeline you're getting the error from (scroll looking for screenshots of something that resembles your error), make changes to get something new, repeat.
First determine what error message you are actually seeing.
If you are seeing the file located here...
%SystemDrive%\inetpub\custerr<LANGUAGE-TAG>\500.htm
...which generally looks like this:
**...then you know you are seeing the currently configured error page in IIS ** and you do NOT need to change the ASP.net customErrors setting, asp error detail setting, or "show friendly http errors" browser setting.
You may want to look at the above referenced path instead of trusting my screenshot just in case somebody changed it.
"Yes, I see the above described error..."
In this case, you are seeing the setting of <httpErrors> or in IIS Manager it's Error Pages --> Edit Feature Settings. The default for this is errorMode=DetailedLocalOnly at the server node level (as opposed to the site level) which means that while you will see this configured error page while remote, you should be able to log on locally to the server and see the full error which should look something like this:
You should have everything that you need at that point to fix the current error.
"But I don't see the detailed error even browsing on the server"
That leaves a couple of possibilities.
The browser you are using on the server is configured to use a proxy
in its connection settings so it is not being seen as "local".
You're not actually browsing to the site you think you are browsing to - this commonly happens when there's a load balancer involved. Do a ping check to see if dns gives you an IP on the server or somewhere else.
Your site's httpErrors settings is set for "Custom" only. Change it to "DetailedLocalOnly". However, if you have a configuration error, this may not work since the site level httpErrors is also a configuration item. In that case proceed to #4
The default for httpErrors for all sites is set for "Custom". In this case you need to click on the top level server node in IIS Manager (and not a particular site) and change the httpErrors settings there to DetailedLocalOnly. If this is an internal server and you're not worried about divulging sensitive information, you could also set it to "Detailed" which will allow you to see the error from clients other than the server.
You're missing a module on the server like UrlRewrite (this one bites me a lot, and it often gives the generic message regardless of the httpErrors settings).
"Logging on to the server is not an option for me"
Change your site's httpErrors to "Detailed" so you can see it remotely. But if it doesn't work your error might already be a config error, see #3 immediately above. So you might be stuck with #4 or #5 and you're going to need somebody from your server team.
"I'm not seeing the error page described above. I'm seeing something different"
If you see this...
...and you expect to see something like this...
...then you need to change "Send errors to browser" to true in IIS Manager, under Site --> IIS --> ASP --> Debugging Properties
If you see this...
or this...
...you need to disable friendly errors in your browser or use fiddler's webview to look at the actual response vs what your browser chooses to show you.
If you see this...
...then custom errors is working but you don't have a custom error page (of course at this point were talking about .net and not classic asp). You need to change your customErrors tag in your web.config to RemoteOnly to view on the server, or Off to view remotely.
If you see something that is styled like your site, then custom errors is likely On or RemoteOnly and it's displaying the custom page (Views->Shared->Error.cshtml in MVC for example). That said, it is unlikely but possible that somebody changed the pages in IIS for httpErrors so see the first section on that.
In web.config under
<system.webServer>
replace (or add) the line
<httpErrors errorMode="Detailed"></httpErrors>
with
<httpErrors existingResponse="PassThrough" errorMode="Detailed"></httpErrors>
This is because by default IIS7 intercepts HTTP status codes such as 4xx and 5xx generated by applications further up the pipeline.
Next, enable "Send Errors to Browser" under the "ASP" section, and under "Error Pages / Edit Feature Settings", select "Detailed errors".
Also, give Write permissions on the website folder to the IIS_IUSRS builtin group.
try setting the value of the "existingResponse" httpErrors attribute to "PassThrough". Mine was set at "Replace" which was causing the YSOD not to display.
<httpErrors errorMode="Detailed" existingResponse="PassThrough">
One thing nobody's mentioned is as a very quick and temporary fix, you can view the error on the localhost of that web server.
You may also verify that if you changed your main website folder (c:\inetpub\wwwroot) to another folder you must give read permission to the IIS_IUSRS group in the new folder.
Fot people who have tried EVERYTHING and just CANNOT get the error details to show, like me, it's a good idea to check the different levels of configuration. I have a config file on Website level and on Application level (inside the website) check both. Also, as it turned out, I had Detailed Errors disabled on the highest node in IIS (just underneath Start Page, it has the name that is the same as the webservers computername). Check the Error Pages there.
Found it.
http://blogs.iis.net/ksingla/archive/2009/02/16/iis-7-5-updates-to-custom-errors-and-compression.aspx
run cmd as administrator, go to your system32\inetsrv folder and execute:
appcmd.exe set config -section:system.webServer/httpErrors -allowAbsolutePathsWhenDelegated:true
Now I can see detailed asp errors .
If you run the browser in the server and test your url of the project with the local ip you have received all errors of that project without a generally error page(for example 500 error page).
In my case it was permission issue.
Open application folder properties -> Security tab -> Edit -> Add
IIS AppPool\[DefaultAppPool or any other apppool] (if use ApplicationPoolIdentity option)
IUSRS
IIS_IUSRS
Double check the encoding of the asp file you are testing.
For instance if you created a file like below on a Windows Server Core 2019 :
echo "<%# LANGUAGE=Javascript %>" > test.asp
echo "<%Response.Write("test");%>" >> test.asp
Then test.asp will be encoded in Unicode, and requesting it will produce a 500 without any details.
Do a notepad test.asp, then click on "Save As..." and choose "ANSI" encoding to fix it.

Taking my ASP.NET from my local comp to the server

So I have been developing a small ASP.NET web app in C# for my company over the past few weeks and now I am trying to push it onto our Rackspace server. First step was to create a virtual directory because we want it to be www.ourdomain.com/appname/ and most of the stuff on ourdomain.com is currently in classic ASP. So I did this and then uploaded my stuff to the new folder. I *think* I did this at least semi-right because the error message I am getting is that nice puke color (ASP.NET style instead of classic ASP style) -- problem is it is generic and just saying runtime error. I tried just copy/pasting <customErrors mode="On" /> into the web.config file in the /appname/ directory but nothing changed
So the actual questions are:
How can I get a more descriptive error, when I was developing locally I just pushed the "play button" in VS2010 and it would either show me the app or tell me where I screwed up
Is there anything else I'm doing wrong that may be causing this? If there's things I need to check lemme know!
> I tried just copy/pasting
> <customErrors mode="On" /> into the
> web.config file in the /appname/
> directory but nothing changed
You need <customErrors mode="Off" />
If you can go with remote desktop in your server you can load your page under rd and you'll have your error message.
You can also see it in the event viewer.
Or you can catch the exception in your global.asax :
http://www.nikhedonia.com/notebook/entry/three-ways-to-catch-exceptions-in-asp-net/
see under "Catching Exceptions at the Application Level"
where you can send the exception details to your mailbox or in a file for instance.
I think you want to turn off customErrors. You might also want to log all errors by capturing the event in the Application_Error event on the global.asax page.
Listen to exactly what that message is telling you to get a more descriptive error message. By default, the error messages are only detailed when accessing the site from the server computer (in your dev environment, that would be YOUR computer, but not once you deploy to your server). Once you set the settings just how that screen tells you, you should see the full error message.

Resources