SqlMembershipProvider 在开发计算机和服务器上给出不同的结果(?)
我正在尝试部署一个 ASP.NET 应用程序。我真的很讨厌它。
不管怎样,它的一部分是通过使用 SqlMembershipProvider
的表单身份验证来保护的。我已将成员资格提供程序配置为通过 Web.Config 使用 SQL Server 实例。
我可以通过 Visual Studio 使用“ASP.NET 配置”工具来创建新用户。这似乎工作正常,并为每个用户在数据库表中创建一个新行。
然后,我可以使用新创建的凭据登录受保护区域。
这一切在 Visual Studio 开发调试服务器上运行良好。
当我将其部署到服务器时,问题就出现了。将项目的整个目录树(包括 Web.Config)复制到服务器并尝试使用完全相同的凭据登录后,它告诉我“您的登录尝试未成功。请尝试再次。”
这怎么可能?
呃,我讨厌部署。
更新
我将以下代码添加到登录页面。当我单击服务器托管的页面时,可以在服务器上使用凭据进行登录。
protected void CreateAdminButton_Click(object sender, EventArgs e)
{
System.Web.Security.Membership.DeleteUser("admin");
System.Web.Security.Membership.CreateUser("admin", "asdfasdf", "[email protected]");
}
新的管理记录在同一数据库中可见。那么管理员凭据不能用于从开发计算机登录。这向我建议了某种在服务器和开发盒上使用不同密钥的密钥哈希算法。
I'm trying to deploy an asp.net application. I really suck at it.
Anyway, parts of it are protected using Forms Authentication using SqlMembershipProvider
. I've configured the membership provider to use a SQL server instance via Web.Config.
I can use the "ASP.NET Configuration" tool via Visual Studio to create new users. That seems to work fine, and creates a new row in the database table for each user.
I can then log in to the protected areas using the newly created credentials.
That's all working nicely on the Visual Studio development debugging server.
The problem comes when I deploy it to the server. After copying the entire directory tree (including Web.Config) for the project to the server and trying to log in, using the exact same credentials, it tells me "Your login attempt was not successful. Please try again."
How is this possible?
Ugh, I hate deployment.
Update
I added the following code to the login page. When I click on the page hosted from the server, the credentials can be used on the server to log in.
protected void CreateAdminButton_Click(object sender, EventArgs e)
{
System.Web.Security.Membership.DeleteUser("admin");
System.Web.Security.Membership.CreateUser("admin", "asdfasdf", "[email protected]");
}
The new admin record is visible in the same database. The admin credentials can not be used to log in from the dev machine then. This suggests some kind of keyed hash algorithm using different keys on server and dev box to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保在会员资格提供程序中使用“/”作为应用程序名称参数,并定义自定义角色提供程序。我几天前才遇到这个问题。
您现在必须手动清理数据库,因为应用程序表中可能有 2 行,并且用户和角色表中有重复行。
请参阅http://cdonner.com/forms-authentication-custom-membership -provider-gotchas.htm。
Make sure you use "/" for the application name parameter in your Membership provider, and define a custom Role provider as well. I just ran into this a few days ago.
You will now have to clean up the database manually, because you likely have 2 rows in the application table, and duplication in the user and role tables.
See http://cdonner.com/forms-authentication-custom-membership-provider-gotchas.htm.