Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET site auto-login during development

While developing an ASP.NET site, is the a way to setup automatic login?

For example, each time I build the site and run it, I have to login again. I don't want to disable security entirely, but I would like to automate the process of logging in while I'm working on the site.

like image 521
Adam Kane Avatar asked May 11 '11 15:05

Adam Kane


1 Answers

Just keep your browser open and Ctrl+F5 after you modify and/or recompile in Visual Studio. This will keep the authentication cookie.

Another possibility is to setup an automatic login page in which you would test whether you are in Debug mode and force a Login by using FormsAuthentication.RedirectFromLoginPage("someusername", false);. Then you could instruct Visual Studio to always run the web site at this url:

protected void Page_Load(object sender, EventArgs e)
{
    #if DEBUG
    FormsAuthentication.RedirectFromLoginPage("someusername", false);
    #endif
}

Ideally this page should be excluded from the build process and never shipped.


As pointed out in the comments section by @Mufasa if your site uses Session you might need to use out of process mode (StateServer or SqlServer) instead of InProc because when you recompile the application domain will be reloaded and everything stored in memory lost.

like image 179
Darin Dimitrov Avatar answered Sep 20 '22 10:09

Darin Dimitrov