Show message when web service is down - asp.net

How to show the custom message when the web service which is use in web application is down.

You can use the app_offline.htm file on the root, that is the file that show the custom message

When you invoke the web service, if it's down, use the 'CustomErrors' attribute in the web.config to go to your custom error page. You can tailor it to display different messages based on error code.
<error statusCode="500" redirect="InternalError.htm"/>

Related

Custom error pages in web.config file are not covering all url paths

In my web.config file I have specified some custom errors:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error">
<error statusCode="500" redirect="~/Error" />
<error statusCode="404" redirect="~/NotFound" />
</customErrors>
Now, some links, such as http://mysite.com/dsflhsdff will be properly redirected to mysite.com/notfound. But some links, like https://mysite.com/videoconference/0/0/0 are handled by server itself - instead of my custom error page, I am getting IIS error page (file or dir not found). In example this link - https://scyk.pl/forums/0/0/0 will produce proper 404 error (my custom error page).
What is happening here? Do I need to set up IIS custom errors manually? If so, how can I do that?
If the page call is not pass the asp.net engine, then yes is handle by IIS.
You can do that setup very easy if you have direct access to the iis, but IIS gives you the option to setup this custom errors also direct from the web.config of your site. Here is an example for the 404 error:
<system.webServer>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/PageNotFound.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
More info at: http://www.iis.net/configreference/system.webserver/httperrors
This is because ASP.NET never even knows that there has been a request for the .htm page. IIS will handle .htm pages by itself without involving ASP.NET at all.
You can get your custom page to show in one of two ways:
Get ASP.NET to process .htm pages: In IIS rightclick your website/virtual directory --> properties --> home directory/virtual directory tab --> "configuration" button under the "application settings" section --> Add the mapping.
Set the custom error page for IIS: In IIS rightclick your website/virtual directory --> properties --> custom errors tab --> set the 404 error to the page your error page.
You can also handle this error in your Global.asax file in Application_Error method
e.g.
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception exc = Server.GetLastError();
// Handle HTTP errors
if (exc.GetType() == typeof(HttpException))
{
// The Complete Error Handling Example generates
// some errors using URLs with "NoCatch" in them;
// ignore these here to simulate what would happen
// if a global.asax handler were not implemented.
/*if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
return;*/
//Redirect HTTP errors to HttpError page
/*Server.Transfer("HttpErrorPage.aspx");*/
}
}
More info :
http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/aspnet-error-handling
This is happening because IIS is unable to locate your custom error page in some instances. This happened to me with certain extensions, but by configuring my custom error page in the Error Pages portion of IIS manager I was able to hit my custom error page every time.
Heres how to do that:
Go into your IIS Manager and select the site in question, find the icon entitled 'Error Pages' under the IIS section.
After you double click the icon, you will be presented with a list of status codes and the corresponding file responsible for delivering the error.
Find the error code, in your case 404 (if it does not exist you can add it from the right side menu by clicking on 'Add...'), then click on the 'Edit...' button in the right side menu.
Next, click the radio button for 'Execute a URL on this site' in the dialog box you have been presented with. Here is where you provide the relative URL that the user will be redirected to.
After you have completed the options in the Edit dialog box, you are going to want to select your page in the main Error Pages pain again, only this time click 'Edit Feature Settings...'
In the Edit Error Pages Settings you are presented with, ensure that 'Detailed errors for local requests and custom error pages for remote requests' is selected. Also ensure the page you entered in the previous Edit menu is entered in the Path field in the Default Page portion of the Edit Error Pages dialog box. Finally, Path Type must be set to 'Execute URL'

ASPX page within a .aspx page with iframe throws 500.23 error

I'm trying to embed a ChartModule.aspx page within a Default.aspx page using an iframe.
The ChartModule has a button event which updates a chart. The ChartModule has its own ChartsModule.cs.
I'm getting this error:
HTTP Error 500.23 - Internal Server Error An ASP.NET setting has been
detected that does not apply in Integrated managed pipeline mode.Most
likely causes:
•This application defines configuration in the system.web/httpHandlers
section. Things you can try: •Migrate the configuration to the
system.webServer/handlers section. You can do so manually or by using
AppCmd from the command line. For example, from the IIS Express
install directory, run appcmd migrate config "Default Web Site/".
Using AppCmd to migrate your application will enable it to work in
Integrated mode. It will continue to work in Classic mode and on
previous versions of IIS. •If you are certain that it is OK to ignore
this error, it can be disabled by setting
system.webServer/validation#validateIntegratedModeConfiguration to
false. •Alternatively, switch the application to a Classic mode
application pool. For example, from the IIS Express install directory,
run appcmd set app "Default Web Site/"
/applicationPool:"Clr4ClassicAppPool". Only do this if you are unable
to migrate your application.
Detailed Error Information: Module ConfigurationValidationModule
Notification BeginRequest Handler
PageHandlerFactory-Integrated-4.0 Error Code 0x80070032 Requested
URL http://localhost:4161/Default.aspx Physical Path
C:\Documents and
Settings\singhm\Desktop\Temp\Trial2\Trial2\Default.aspx Logon Method
Not yet determined Logon User Not yet determined Request Tracing
Directory
Why is this?
While this may not answer your question directly, here is a thought:
If you have the option, consider turning ChartModule.aspx into a UserControl (ascx), which acts just like another "page" (same lifecycle, its own codebehind file, etc) but integrates more cleanly into an existing aspx page. The above link should be a good introduction to creating and using UserControls.
The error message contains a clue to the solution:
setting system.webServer/validation#validateIntegratedModeConfiguration to false
So make sure the following is present in your web.config:
<validation validateIntegratedModeConfiguration="false"/>
For example:
<configuration>
<!-- your existing settings -->
<system.webServer>
<!-- Add this to here.... -->
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
IIS 7 and ASP.NET are quite helpful these days with regard to to error messages and hints contained therein so you should take the time to read them.
I would really recommend using a usercontrol page instead of iframes in asp.net this way you can bind that usercontrol by doing
public override DataBind()
in that you can pass anything into that usercontrol page like refresh data, load certain data, etc..

404 error page not showing

I've got this in my web.config and it's being hosted by the DiscountASP.net ISP
<customErrors mode="On" defaultRedirect="">
<error statusCode="404" redirect="404.aspx"/>
<error statusCode="500" redirect="404.aspx"/>
</customErrors>
I am hosting the site on DiscountASP.net and they also tell you to config it this way. I'm using Enterprise Library but I don't think that should make a difference. I don't believe I need to config anythign for a 404 in EL.
When my page loads with an error, my 404.aspx doesn't show and I get the default custom errors off message. I do not know why I don't get my 404.aspx page showing and get this instead:
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".
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.
Have you tried using a relative path to see if that makes a difference?
<error statusCode="404" redirect="~/404.aspx"/>
Alternately, try an absolute path:
<error statusCode="404" redirect="http://www.domain.com/errors/404.aspx"/>
EDIT: As others have pointed out, and based on your comment to another answer, the 404 error page should be displayed when someone navigates to a page that doesn't exist, whereas general errors on a page could be captured by the defaultRedirect. So if you're testing the 404 then make sure you're testing with a nonexistent page. To test the defaultRedirect then have one of your pages throw an exception etc.
Is it possible that you are overriding this in another web.config, say in a sub folder? Or we can go the other way. Are you sure this is in the application root?
Is there any reason why you don't want to use the defaultRedirect for 500 errors?
You are FTP-ing the files correct? Try uploading the file as a binary file instead of text. You might be suffering from an encoding problem. I'm willing to bet right now that nothing you are doing in your web.config is working.
I found a solution here.
The real catch was using this:
Response.TrySkipIisCustomErrors = true;

Error Handling URLS that do not exist

I'm having problems with handling URLS that do not exist...
In my development environment, I navigated to http://localhost:XXXX/FakeLocation and would catch the HttpException and handle it properly.
When I deployed to my production location, I'm getting a 404 error when I navigate to http://MyProductionURL/FakeLocation. How can I make the production location throw the HttpException so my code can handle it similar to how it works in my development environment?
ASP.NET will only handle file extensions it is registered in IIS to handle. So if the page was foo.aspx, then by default, ASP.NET returns the 404 page as set in the web.config. And by default 404 for foo.xyz will be handled by IIS because IIS handles anything that doesn't have a mapping.
This page shows how to set up wildcard mapping so that all requests, regardless to extension are handled by asp.net.
You probably need to configure IIS on the production location. The easiest thing you can probably do is
Go to the Control Panel, and under Administrative Tools open Internet Information Services (IIS).
Right-click on your web site to bring up the properties.
Go to the Custom Errors tab
Select to the 404 error and edit properties on it.
Change the Message Type to URL.
Set the URL to the page you want them redirected to.
you can do this in the custom errors node of the web.config
<configuration>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly">
<error statusCode="500"
redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
Msdn Reference
Looks like IIS handle this exception and does not pass error to ASP.NET.
Please check http://www.chat11.com/How_To_Setup_A_Custom_404_Error_Handler_In_.NET

Turn off customErrors for web service only

My ASP.NET 2.0 web app includes a web service, which throws various exceptions along with custom error messages (e.g. "You do not have access to this item" etc.). These are shown on screen, in a ASP.NET AJAX callback handler.
The rest of the app is covered by some custom error pages, specified in the usual way in web.config.
<customErrors mode="RemoteOnly" defaultRedirect="Error.html">
<error statusCode="404" redirect="NotFound.html" />
<error statusCode="403" redirect="NoAccess.html" />
</customErrors>
My problem is if I have customErrors enabled in web.config, I lose my error messages returned from the web service - instead they are replaced with
"There was an error processing the request" - which isn't very useful for either me or the users.
Is there a way to turn off custom errors for just the web service?
Put your web service into separate directory and put additional web.config file in this directory. Each directory can have it own web.config containing settings of this directory (and directories inside this directory).
Yes, the custom errors element
can be defined at any level in the application file hierarchy.
So provided your WebService is in a folder you can add a web.config for that folder and turn them off.

Resources