I have a Mono web application with an included setup form. In order to detect if the application is installed or not, I create a marker fi开发者_开发技巧le _INSTALL_LOCKFILE_ that, if exists, is able to tell that the program is installed (and so Setup will refuse to run again).
My question is: how do I redirect the user to the setup script ("~/Setup/Default.aspx") the first time he accesses the web application? If user attemts to run the "empty" application he will definitely get unreadable exceptions.
I have thought about using HttpApplication.BeginRequest
event in Global.asax, or other request-related events, to choose if redirecting or not.
My doubts are
- If I say "redirect every request but all that were directed to /Setup/* I will surely be unable to download CSS and images, stored in App_Themes
- I would not like to enumerate all pages in my web application to write the redirect rules
So, my question is
How would you redirect the user to a setup script in ASP.NET when you detect that the web application has not been configured yet?
Looking at the life cycle of an application, I think I'd prefer to put such a method in the Application_Start method
http://msdn.microsoft.com/en-us/library/ms178473.aspx
protected void Application_Start()
{
if (!MyLockedFileExists()) {
HttpContext.Current.Response.Status = “302 Found”;
HttpContext.Current.Response.AddHeader(“Location”, “http://www.newlocation.com/newwebpage.aspx”);
}
}
note: MyLockedFileExists
would be a custom bool method that checks for your lock file
精彩评论