开发过程中 ASP.NET 站点自动登录 [英] ASP.NET site auto-login during development

查看:33
本文介绍了开发过程中 ASP.NET 站点自动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发 ASP.NET 站点时,有没有设置自动登录的方法?

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.

推荐答案

在 Visual Studio 中修改和/或重新编译后,只需保持浏览器打开并 Ctrl+F5.这将保留身份验证 cookie.

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

另一种可能性是设置一个自动登录页面,您将在其中测试您是否处于调试模式并使用 FormsAuthentication.RedirectFromLoginPage("someusername", false); 强制登录.然后,您可以指示 Visual Studio 始终在此 url 上运行网站:

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.

正如@Mufasa 在评论部分指出的那样,如果您的站点使用 Session,您可能需要使用进程外模式(StateServer 或 SqlServer)而不是 InProc 因为当您重新编译应用程序域时重新加载,存储在内存中的所有内容都会丢失.

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.

这篇关于开发过程中 ASP.NET 站点自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆