Write and display error message for live website? - c#

I am developing a website, At the moment when i run it off my local host every thing works fine.
I have uploaded this website to fireFTP and can now access my website online.
The website does not preform the same as when hosted on local host and i cant find the errors as my website does not break.
I would like to do some testing and am wanting to know how to display an error message??
I would like to display the error message like this:
But with a custom message like, "code stepped into method writeToSpreadSheet".
This way i could find where my code gets to and pin point whats going wrong.

You need to enable show detailed error messages in IIS settings, see the link below for a short tutorial about how to do it.
IIS7 : HOW TO enable the detailed error messages for the website while browsed from for the client browsers?

Add this lines in web.config inside so you dont have
to touch the IIS configuration:
<customErrors mode="On">
<error redirect="error404.html" statusCode="404" />
</customErrors>
Change the error404.html for your desired html page.
When some page is not found user will be redirected there

Related

ASP.NET display "site down" page instead of YSOD if failure during startup

I'm trying to serve a custom "site down" page instead of the standard YSOD if the server were ever to fail during it's startup. Using <customErrors> inside of web.Config work's fine for any server error occurring after startup has completed successfully, but in this case the YSOD response is not replaced.
Other resources have lead me to adding app_offline.htm to the root of the project and playing with its name during deployment, but this does not tackle unexpected server issues occurring during startup.
Is there a way to serve a "default" page if there are any errors or a proper HTTP response could not be formed?
Yes there is a way to do that but that depends how you want to handle those errors.
If you want to redirect to the same error page on any 4xx or 5xx status codes then you can use the below code in your web.config file
<customErrors mode="On" defaultRedirect="Error.aspx">
</customErrors>
In error page you can display some user friendly message.

asp dot net web config key Base URL issue

I got an issue during test my asp dot net web based application. In the Page there is an "Slip button" and when I click the button new pop up page should open with details.
But i got server error '/' 404 error instead of page. After went some analysis found that in my web.config it is mentioned as below
<add key="BaseURL" value="http://xxxx.xx.xxx.com/arf/" />
I changed to localhost as below
<add key="BaseURL" value="http://localhost/arf/" />
it is working fine. why it is working when I changed to localhost. This is in windows server.
The same issue occurs in Production ( the application runs in )HP Unix environment.
How to fix this in Production Do I need to changed to localhost or How the url works with Domain name.
Any thing I need to change in IIS.Please help on this.
Thanks in Advance

Google+ signin "Getting Started" project - problems with IIS

Using the C#/.NET Google+ sign-in quick start project, I'm hitting problems with IIS6. Here are the steps I followed:
downloaded the project from Github
modified the index.html and signin.ashx files to contain my Client ID and Client Secret
running the project on my machine (using the built in web server for Visual Studio 2010) works fine
published to Windows 2003 server with IIS6
added "index.html" as a default document for the web site
set the web site to use an app pool configured for the 4.0 .NET framework
attempted to access the page from Chrome
Accessing the site with no page specified on the URL (https://myserver.com/gplussample/) brings up the Google+ signin button. This works great and I'm taken to the page with my profile photo, circles, etc.
However, when I click the "disconnect" button, nothing happens. Using Chrome DevTools to examine the process, I see this error:
POST https://myserver.com/gplussample//disconnect 404 (Not Found)
The problem is the //disconnect - there's no page name (I believe it should be signin.ashx, as that's what works when I'm running the app on the dev web server with Visual Studio 2010).
I then attempted to access the site with a page name specified:
https://myserver.com/gplussample/signin.ashx
That results in a blank page and again, looking at the Chrome DevTools, I see a 400 Bad Request error for the .ashx handler. I searched and searched for solutions for .ashx handlers and "bad request" errors, with no success in this particular case.
Thinking IIS6 was the culprit, I published the site to an IIS7 instance.
With no page name specified on the URL (http://localhost/gplusoriginal/), I encountered the same error with the "disconnect" button - no action and a 404 error.
When I changed the URL to http://localhost/gplusoriginal/signin.ashx, I received this error:
Could not create type 'GPlus_ServerSideFlow.Signin'.
Again, back to Google and checking on .ashx handlers and issues with IIS7. I found a post about the web.config and specifying the handler there, so I tried that.
<system.webServer>
<handlers>
<add name="GPlus_ServerSideFlow.Signin" path="*.ashx" verb="*"
type="GPlus_ServerSideFlow.Signin" resourceType="Unspecified" />
</handlers>
</system.webServer>
Adding this snippet to the web.config resolved the "could not create type" error, but resulted in another 400 Bad Request error.
So, my questions are: What has to be done with II6 or IIS7 to get this sample project working? Are there additional steps in configuring IIS that need to be completed? Or something missing from the project code?
Thank you
The way that the sample works is that the RESTful endpoints are intercepted by an ashx handler, signin.ashx.cs. The handler can't be directly addressed so routes are setup in global.ashx.cs to map endpoints (/, /connect, /disconnect, etc) to that route handler.
As the sample ships, it assumes the built-in web server running on the root port. When moving to IIS, you need to change the path matchers from Equals to EndsWith in order to match the virtual directory you are deploying to:
// Redirect base path to signin.
if (context.Request.Path.EndsWith("/"))
{
context.Response.RedirectPermanent("signin.ashx");
}
// This is reached when the root document is passed. Return HTML
// using index.html as a template.
if (context.Request.Path.EndsWith("/signin.ashx"))
{
Apologies for the delay on this... but hopefully that fixes it! This fork of the C# starter has the changes in it, tested with IIS, and this update may end up getting merged back into the official sample soon.

asp.net suppress internet explorer error dialog box

This is only supposed to work on IE 8.0
On my asp.net page, I press the save button and it goes through some server side code. Upon an error on server side code, on the web page, I get Internet Explorer Error dialog titled "Errors on this webpage might cause it to work incorrectly". I know exactly what is causing this error on server side.
I do not have try catch handling in my webpages. I bubble up all my errors to Global.asax and log them in the event Application_Error.
So.. my questions are
1. How do I suppress this pop up Internet Explorer Error dialog?
2. How do I In Application_Error in Global.asax, redirect to another asp.net page called GenericErrPage.aspx where I display user friendly custom text message.
Please help. Thanks.
all I had to do was to add the following line in system.web section in web.config and it stopped the dialog box from popping up. Also, I was able to log the err in Application_Error in Global.asax file.
<customErrors defaultRedirect="~/CustomError.aspx" mode="On" />

Validation of viewstate MAC failed -View State Error

In my website, when a web page is idle for more than 5 minutes, then that page is not working until I refresh. The following error occurs:
Error:
Sys.WebForms.PageRequestManagerServerErrorException:
Validation of viewstate MAC failed. If
this application is hosted by a Web
Farm or cluster, ensure that
configuration specifies
the same validationKey and validation
algorithm. AutoGenerate cannot be used
in a cluster.
I'm already using EnableEventValidation="false" ViewStateEncryptionMode="Never" ValidateRequest="false"
But, nothing is working for me.
Although it's an old question, I will answer anyway because it might help someone else.
So I had this problem in the past few days, and I realized that I started getting this error after I configured my cookies as HttpOnly and Require SSL:
</system.web>
<httpCookies httpOnlyCookies="true" requireSSL="true" />
</system.web>
Turns out that I just forgot to configure Visual Studio to open the SSL URL of my website. So as long as it opened the regular Url, the cookies couldn't be sent, and that what caused the error.
In order to change the default Url, you simply need to figure out what is your SSL url: Click the project on solution explorer and press F4 (not Right Click -> Properties) and over there you'll see SLL URL under the the Development Server section. After that, go to the project properties page (Right Click -> Properties) and in the Web tab, put the SSL Url as the Project Url.
Make sure all the servers on the cluster are using the same encryption key.
This sometimes happens if you are doing a postback from a form which has an action pointing to a different page.

Categories