虽然开发一个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.
推荐答案只要保持你的浏览器中打开和 Ctrl + F5键后修改和/或在Visual Studio重新编译。这将保持身份验证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,假)强制登录; 。然后,你可以指示Visual Studio中总是在这个网址运行网站:
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评论部分中指出,如果您的站点使用会话,你可能需要使用进程外模式(或的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站点自动登录
发布评论