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 站点自动登录


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01