ASP.NET 成员资格 - 登录在本地工作,在 Azure 上失败 [英] ASP.NET Membership - login works locally, fails on Azure

查看:34
本文介绍了ASP.NET 成员资格 - 登录在本地工作,在 Azure 上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 MVC3 站点上工作,我遇到了一个关于 ASP.NET 成员资格的令人费解的问题.我使用 System.Web.Providers 1.0.1 连接到 SQL Azure 数据库.

I'm working on an MVC3 site, and I've got a puzzling problem with ASP.NET Membership. I'm using System.Web.Providers 1.0.1 connected to a SQL Azure database.

就像现在一样,在 Compute Emulator 下运行时登录我的相同用户名/密码在 Azure 下运行时失败.我可以看到它使用了正确的数据库,因为正在更新成员数据库中的 Failed Password Attempts 计数器.

As it is now, the same username/password that logs me in when running under the Compute Emulator fails when running under Azure proper. I can see that it's using the right database, as the Failed Password Attempts counter in the membership database is being updated.

推荐答案

我找到了它,感谢 David Hoerster 撰写的这篇文章.问题在于 Azure 上的默认密码哈希算法与 .NET 4.0 默认值不同.它在 Azure 上设置为 SHA1,而 HMACSHA256 是 4.0 上的新标准设置.

I tracked it down, thanks to some info in this article by David Hoerster. The problem is that the default password hashing algorithm on Azure is different from the .NET 4.0 defaults. It is set to SHA1 on Azure, and HMACSHA256 is the new standard setting on 4.0.

这可以通过在 web.config 中明确指定哈希类型来解决.如果您决定使用 HMACSHA256 之类的方法,请确保还指定了机器密钥 - 否则您会遇到类似问题,因为自动生成的机器密钥因服务器而异.

This can be fixed by specifying the hash type explicitly in web.config. If you decide to use a method like HMACSHA256, make sure you also specify a machine key - otherwise you will run into similar problems as the autogenerated machine key will differ from server to server.

您需要更改的配置元素是下的:

The configuration element you need to change is <machinekey> under <system.web>:

<machineKey decryptionKey="PUT_DECRYPTION_KEY_HERE"
            validationKey="PUT_VALIDATION_KEY_HERE"
            decryption="AES"
            validation="HMACSHA256" />

您可以使用 这个机器密钥生成器以正确的格式生成随机密钥.

You can use this machine key generator to generate random keys in the proper format.

这篇关于ASP.NET 成员资格 - 登录在本地工作,在 Azure 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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