Stop processing request and redirect to file
Hi i have mvc2 application where i want to stop processing application when settings file is set to offline and display offline page to the user.
i have decided to create in global.asax.cs switch that will check it web application is offline and pending result it will redirect to offline page or continue with processing page.
how ever when i try to run it with this code i get error:
开发者_StackOverflow社区Server Error in '/' Application. Response is not available in this context. 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.Web.HttpException: Response is not available in this context.
Source Error:
Line 25: if (!this.IsApplicationOnline()) Line 26:
{ Line 27: Response.Redirect("~/Content/offline.html", true); Line 28: } Line 29: elseSource File: *\Global.asax.cs Line: 27
Stack Trace:
[HttpException (0x80004005): Response is not available in this context.] System.Web.HttpApplication.get_Response() +3002456
easyccms.WebUI.MvcApplication.Application_Start() in *Global.asax.cs:27
My code is as follows
protected void Application_Start()
{
if (!this.IsApplicationOnline())
{
Response.Redirect("~/Content/offline.html", true);
}
else
{
AreaRegistration.RegisterAllAreas();
log4net.Config.XmlConfigurator.Configure();
RegisterRoutes(RouteTable.Routes);
}
}
Ok i have found a solution.
I had to specify which response it is and therefore: added System.Web.HttpContext.Current
and this works. Now i just presume there can be more then httpcontext
System.Web.HttpContext.Current.Response.Redirect("~/Content/offline.html", true);
精彩评论