2

I have this entry in web.config

  <appSettings>
    <add key="pingUrl" value="http://examplesite.com/login.aspx"/>
  </appSettings>

I have the below code in Global.asax.cs to automatically start the IIS when it is recycle

void Application_End(object sender, EventArgs e)
    {
        try
        {
            string pingUrl = ConfigurationManager.AppSettings["pingUrl"];
            WebClient http = new WebClient();
            string Result = http.DownloadString(pingUrl);
        }
        catch (Exception ex)
        {
            string Message = ex.Message;
        }
    }

My Question is can I detect the application forms authentication login page url in Application_End method some how? Instead of reading entry from <appSettings/>

Note: I am using Quartz.Net in my MVC4 application and it is stop working when IIS recycle. I read IIS app pool recycle + quartz scheduling and many SO links but no use. We use external hosting provider, so we dont have a control of changing a physical config file.

After reading http://weblog.west-wind.com/posts/2007/May/10/Forcing-an-ASPNET-Application-to-stay-alive I decided to go with this solution.

Community
  • 1
  • 1
Billa
  • 5,226
  • 23
  • 61
  • 105

1 Answers1

1

Check out the MSDN docs on FormsAuthentication.LoginUrl.

If you have your forms authentication set up in web.config's <authentication> element, and you have the "loginURL" populated there, then the property mentioned above should have the information you're looking for.

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
  • It gives `/~/Home/Index` not the fully qualified url to use in a `WebClient.DownloadString` method – Billa Jun 20 '14 at 12:10
  • @Billa So you're almost there =) You just need to build the URL from there. There are some great answers on how to do that here: [How do I turn a relative URL into a full URL?](http://stackoverflow.com/questions/126242/how-do-i-turn-a-relative-url-into-a-full-url) – Josh Darnell Jun 20 '14 at 12:18
  • The problem is will not be have an access to Request object in Application_End, since this will be called when IIS is recycling and there wont be any url request made :( – Billa Jun 20 '14 at 12:55
  • @Billa I think the best thing you can do, then, is code it in your gloabl.asax function as a `const string`. Since you can't add appSettings and whatnot. – Josh Darnell Jun 20 '14 at 14:20
  • Also, @Billa - it sounds like Forms Auth is not set up properly in web.config, if your LoginURL is set to the homepage. – Josh Darnell Jun 20 '14 at 14:21
  • I have the forms authentication setup and that why I am getting relative url. We will be hosting this application in many servers and of course we can't hard code the value in global.asax.cs. – Billa Jun 20 '14 at 15:20