Configure forms authentication without Web.Config

Scenario


I configured the MVC application to use Forms authentication in the traditional way.

<authentication mode="Forms">
  <forms cookieless="UseCookies" slidingExpiration="true" timeout="1">
  </forms>
</authentication>

However, I allow the client to choose the authentication method of their web application (URL Token / Cookie), as well as how long their application session should last until the expiration (Timeout)

Question


Is there any way to do this with code? I just saw implementations of this via web.config?

I would like to read the settings from the database and apply them in Global.asax -> OnApplicationStart ()

+4
source share
1 answer

WebActivatorEx. blog . FormsAuthentication, . WebActivatorEx . [: PreApplicationStartMethod (typeof (AppConfig), "Configure" )] AssemblyInfo.cs, . , .

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(AppConfig), "Configure")]
public static class AppConfig
{
    public static void Configure()
    {
        var settings = new NameValueCollection();
        settings.Add("defaultUrl", "~/Account/Default.aspx");
        settings.Add("loginUrl", "~/Default.aspx");
        settings.Add("timeout", "10");
        FormsAuthentication.EnableFormsAuthentication(settings);
    }
}
+2

All Articles