ASP.NET site auto-login during development(开发过程中 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 站点自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:开发过程中 ASP.NET 站点自动登录
- 带问号的 nvarchar 列结果 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
