Asp.net mvc 4 如何获得网站安全性。登录工作?
我正在尝试使MVC4的默认登录模型正常工作,但开箱即用,我认为我做得不对。这是默认代码:Asp.net mvc 4 如何获得网站安全性。登录工作?,asp.net-mvc-4,Asp.net Mvc 4,我正在尝试使MVC4的默认登录模型正常工作,但开箱即用,我认为我做得不对。这是默认代码: if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } 生成、运行并尝试登录时,出现以下错误: An exception of type 'System.InvalidOperationExceptio
if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
生成、运行并尝试登录时,出现以下错误:
An exception of type 'System.InvalidOperationException' occurred in WebMatrix.WebData.dll but was not handled in user code
Additional information: To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
我认为这是我的提供商资源的问题,但我已经安装了Entity First Tools 6.0.2、System.web.providers和Microsoft.aspnet.providers.core,并且仍然存在此问题。我发现了一些迹象,可能是因为我正在连接SQL数据库,但找不到解决方案
有人指出我需要使用System.Web.Http而不是System.Web.Mvc,但事实并非如此
这是我的连接字符串:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Server=servername;Initial Catalog=mercury;Integrated Security=SSPI" />
所以,我不知道下一步该看哪里。有几个地方可能出了问题。首先,我将Entity 6降级为Entity 5,因为EF 6支持MVC,MVC使用声明身份模型而不是简单的成员API。您可以转到package manager控制台并选择相关的应用程序
Uninstall-Package EntityFramework Version 6.0.2
然后
希望这能让你走。
您还可以将初始值设定项包装在check方法中
if(!Websecurity.Initialized){
///Initialize Websecurity
}
我无法卸载它,因为它依赖于Microsoft.aspnet.providers.core。我想我得到了这个错误,因为我有一个缺少表列的自定义userprofile数据库。
private void SeedMembership()
{
WebSecurity.InitializeDatabaseConnection("UsersContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
Uninstall-Package EntityFramework Version 6.0.2
Install-Package EntityFramework version 5.0.0
if(!Websecurity.Initialized){
///Initialize Websecurity
}