In my app, I am checking if some config file is available or not, if it's not then I want to redirect to install page.
To me the best place to accomplish this is application_start
. Because it's happening for only one time. If I do the checking in application_start
and write Response.Redirect
I will get Response is not available in this context
.
I tried other answers in stack overflow to redirect in application_start
like HttpContext.Current.Response.Redirect
; none worked for me.
I don't want to do it in a base controller
or a filter
because the checking logic will happen for every single request.
My goal is to check it only once and it's best to be when the app start.
Update 1
I added response.redirect to the application_start but got error like this:
application start:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Response.RedirectToRoute(
new RouteValueDictionary {
{ "Controller", "Home" },
{ "Action", "about" }
});
}
but i am receiving an error like this:
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.