开发者

Redirecting user to a setup script if the web application is not installed

开发者 https://www.devze.com 2023-02-07 05:43 出处:网络
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

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

  1. 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
  2. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消