Special Error Page in Asp.Net - asp.net

i want to redirect to a special page which shows detailed error message for unexpected errors.Which solution is the best for it in asp.net?Can u give examples? Thanks

It sounds like all you really want to do is turn off custom errors in your web.config file:
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
That should cause a full "yellow screen of death" to appear for any unhandled exception. You can also use this to set the behavior so that the full messages only shows up on your local machine, but your users are redirected to something... friendlier:
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="MyErrorPage.aspx" />
</system.web>
</configuration>

Related

Where or how can I get more information about an error 500?

I have managed to publish an asp.net-5 app on a server with IIS, but now I get a 500 Internal Server Error. How can I get more information on what's wrong ?
In the wwwroot/web.config, I have added:
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
I have also temporarily changed the Startup to show errors like in development by commenting out the if (env.IsEnvironment("Development")) around the
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
I also set the Configuration to 'Debug' in the publish wizard, but I still get the error 500 page without further information.
How can I make it display the stack trace and all other debug informations ?
(I also tried to look for the error in the Windows logs but couldn't find anything)
I could get the trace by viewing the page from within the server.
So it actually behaves like when setting the <customErrors mode="RemoteOnly"> in asp.net < 5. I still wonder how to allow remote hosts to view trace in asp.net-5...

Runtime Error in ASP.Net Application

I am modifying a website using asp.net pages which was created using asp. In the web.config file I am using
<system.web>
<compilation debug="true" strict="false" explicit="true" tarrgetFramework="4.0"/>
<httpRuntime requestValidationMode="2.0" maxRequestLength="1048576" executionTimeout="3600" />
<customErrors mode="Off"/>
</system.web>
and also tried
<customErrors mode="RemoteOnly" defaultRedirect="error.htm"/>
But still an error occuring as
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
What is its solution??

The element 'system.web' has invalid child element 'defaultDocument'

I'm training my web.config to recognize what the best default file is. According to my host it's supposed to look like in the listing below.
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings/>
<system.web>
<defaultDocument>
<files>
<clear />
<add value="Defalut.aspx" />
</files>
</defaultDocument>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="4.0"/>
<machineKey/>
<customErrors defaultRedirect="Error.aspx" mode="On"/>
</system.web>
</configuration>
The problem is that VS2012 (Express) marks it blue and claims the error in the subject. First i thought that i could upload it as it is and by brute force make the server to like the file but it then got angry and spat out the following
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
As i read the error message it says that: "The configuration section 'defaultDocument' cannot be read because it is missing a section declaration."
I've done my homework and found the article below but due to the limitation in my situation (e.g. i need to manually upload the web.config file and i can't run any scripts on the server of my hosting company), it was to no avail.
How do i kill this little problem?
"Defalut.aspx" is a definite yellow flag.
SUGGESTION:
Just create a new dummy project with MSVS2012 (I don't have a copy handy, so I can't help you at the moment)
Cut and paste the auto-generated "web.config" into your project and verify that it works.
If it doesn't, make ONLY those MINIMAL changes needed to get a clean compile/execute.
Save a backup of your working web.config
Try adding your "defaultDocument" section and see what happens.
If it still doesn't work, please cut/paste:
a) the exact section (as I presume you did above)
b) the exact error message
ALSO:
Q: It now fails in BOTH your MSVS2012 (running locally) AND your target web server, correct?
Q: Are you sure the target web server is ASP.Net 4.0 capable?
You config looks correct but the error occurs because it cannot find the file that is mean to be the default document for all your website folders
So please replace "Defalut.aspx" with he correct spelling of the file in the below xml
<defaultDocument>
<files>
<clear />
<add value=*"Defalut.aspx"* />
</files>
</defaultDocument>
Late to the party, I know, but for anybody still with a similar problem, I don't believe this has anything to do with the spelling of the default page name (that will probably just give a 404 when it's accessed).
The real issue is that the defaultDocument section should actually be under system.webServer, not system.web. See defaultDocument Element for more info.
So your sample config file should look something like:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings/>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="4.0"/>
<machineKey/>
<customErrors defaultRedirect="Error.aspx" mode="On"/>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Defalut.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>

error: the details of the application error from being viewed remotely

I have 2 login pages: Login.aspx-for customer login and xlogin.aspx for admin login
i just uploaded my project to the server and all application pages works great
but when i log in the admin xlogin.aspx i'm being forwarded to the admin.aspx page - but i get this error:
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
This is my web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<add name="PROJEntities" connectionString="metadata=res://*/PROJModel.csdl|res://*/PROJModel.ssdl|res://*/PROJModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=000.000.0.00;Initial Catalog=DBNAME;User ID=MYUSERNAME;Password=MYPASS;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" timeout="720" slidingExpiration="true" defaultUrl="~/Gateway.ashx"/>
</authentication>
<customErrors mode="Off"/>
<pages enableEventValidation="false" viewStateEncryptionMode="Never"></pages>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization>
<converters>
<add type="PROJ.Presentation.Common.DateTimeConverter" name="DateTimeJavaScriptConverter"/>
</converters>
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
Dear olga is clear what the message says. Turn off the custom errors to see the details about this error for fix it, and then you close them back. So add mode="off" as:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Relative answer:
Deploying website: 500 - Internal server error
By the way: The error message declare that the web.config is not the one you type it here. Maybe you have forget to upload your web.config ? And remember to close the debug flag on the web.config that you use for online pages.
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
This can be the message you receive even when custom errors is turned off in web.config file. It can mean you have run out of free space on the drive that hosts the application. Clean your log files if you have no other space to gain on the drive.
In my case I got this message because there's a special char (&) in my connectionstring, remove it then everything's good.
Cheers

Custom error handling for a specific page in ASP.Net

On a site I run, I have 404's and 500 errors mapped to redirect to a custom error page for end users; using the following code in my web.config:
...
...
<system.web>
<customErrors defaultRedirect="/404/default.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="/404/default.aspx" />
</customErrors>
...
...
However, I have one specific page that I do not want redirected; a health check page to make sure the site is 100% operational. I tried setting a location specific custom error handler using the code below in my web.config:
...
...
</system.web>
<location path="health.aspx">
<system.web>
<customErrors defaultRedirect="" mode="RemoteOnly"></customErrors>
</system.web>
</location>
...
...
However, it doesn't seem to work. When I rename health.aspx to something else like badhealth.aspx, then make a request, I expect to get a generic 404 error via the Yellow Screen of Death page. Similarly, by intentionally changing the code to throw an error, I should get 500 error via the YSOD page. In both cases, I end up being redirected to our custom 404 page, rathen then getting a YSOD. Thoughts?
Any assistance is greatly appreciated.
Thanks all,
- Frank
Nevermind, we solved the issue. It seems when you have a location specific customError directive; if you leave the defaultRedirect as "", it will default to the sitewide defaultRedirect URL.
The solution was simply to turn off CustomError handling for this specific path, like so:
<system.web>
<customErrors defaultRedirect="/404/default.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="/404/default.aspx" />
</customErrors>
</system.web>
<location path="health.aspx">
<system.web>
<customErrors mode="Off"/>
</system.web>
</location>
Thanks anyway, Jose.

Resources