Reputation: 5375
I have a site which has a start up page called Test.htm. The site is temporarily down and we want to display an error page when the site loads. I have a page called error.htm. How is this possible ??
Thanks in advance!
Upvotes: 1
Views: 1231
Reputation: 66649
You can use the app_offline.htm page. If the asp.net find this page on root, then what ever you ask its show this page, and the site is down.
Second way, that is not bring the site down, on Application Begin Request, make the redirect to the page you like as:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string cTheFile = HttpContext.Current.Request.Path;
// just double check in case that htm proceed from asp.net
if(!cTheFile.EndsWith("test.htm"))
{
System.Web.HttpContext.Current.Response.Redirect("test.htm", true);
return;
}
}
Upvotes: 0
Reputation: 4461
You can hack your web.config to force your application into returning 404's when requested. Then override the 404 error page to be you "error" page.
<httpRuntime enable="false" />
<customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx">
<error statusCode="404" redirect="~/error.htm" />
</customErrors>
Upvotes: 0
Reputation: 4188
Just a thought but have looked a response.redirect?
In ASP.NET MVC, how does response.redirect work?
Upvotes: 0
Reputation: 945
ASP.NET provides three main methods that allow you to trap and respond to errors when they occur: Page_Error, Application_Error, and the application configuration file (Web.config).
1.The Page_Error event handler provides a way to trap errors that occur at the page level 2.You can use the Application_Error event handler to trap errors that occur in your application 3.If you do not call Server.ClearError or trap the error in the Page_Error or Application_Error event handler, the error is handled based on the settings in the section of the Web.config file. In the section, you can specify a redirect page as a default error page (defaultRedirect) or specify to a particular page based on the HTTP error code that is raised.
e.g. You need to add following code in Global.asax page customErrors section to redirect the user to a custom page
<customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
</customErrors>
Upvotes: 1