是ASP.NET MVC 5与WebMatrix的SimpleMembershipProvider不兼容? [英] Is ASP.NET MVC 5 incompatible with the WebMatrix SimpleMembershipProvider?

查看:403
本文介绍了是ASP.NET MVC 5与WebMatrix的SimpleMembershipProvider不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个现有的应用程序,这是建立在ASP.NET MVC 4安培;网页API。该网站的管理员部分采用简单的邻人。我感兴趣的升级应用程序MVC 5 /网页API 2,采取一些已添加了新功能。但它看起来像他们可能不兼容。

We have an existing application that was build on ASP.NET MVC 4 & Web API. The admin parts of the site use Simple Membership. I'm interested in upgrading the application to MVC 5 / Web API 2, to take advantage of some of the new features that have been added. But it looks like they might be incompatible.

具体而言,从安装在的NuGet包RC进入项目之一在我的解决方案后,和<一个href=\"http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2\">updating在web.config 的信息,应用程序启动上调用 WebSecurity.InitializeDatabaseConnection(),这个异常的行启动过程中死去:

Specifically, after installing the RC packages from NuGet into one of the projects in my solution, and updating the web.config information, the application starts dying during startup on the line that calls WebSecurity.InitializeDatabaseConnection(), with this exception:

[MethodAccessException: Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.OnConnectionOpened(System.Object, WebMatrix.Data.ConnectionEventArgs)' to access security critical method 'System.Web.WebPages.HttpContextExtensions.RegisterForDispose(System.Web.HttpContextBase, System.IDisposable)' failed.]
   WebMatrix.WebData.PreApplicationStartCode.OnConnectionOpened(Object sender, ConnectionEventArgs e) +70
   WebMatrix.Data.Database.OnConnectionOpened() +70
   WebMatrix.Data.Database.EnsureConnectionOpen() +51
   WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +63
   WebMatrix.WebData.DatabaseWrapper.QueryValue(String commandText, Object[] parameters) +13
   WebMatrix.WebData.SimpleMembershipProvider.GetUserId(IDatabase db, String userTableName, String userNameColumn, String userIdColumn, String userName) +206
   WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable() +87

使用简单的成员,我有

在同一个解决方案的其他项目不的升级,继续努力就好了。

Other projects in the same solution using Simple Membership that I have not upgraded continue to work just fine.

周围的Googling更多信息,变成了大量的点击该异常,当然,但没有什么特别WebMatrix的。

Googling around for more information turns up lots of hits for that exception, of course, but nothing particular to WebMatrix.

FWIW:我知道,微软已经推出了<一个href=\"http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx\">(yet另一个)成员资格和身份解决方案,但除非有到使用与现有的简单会员表,或所有我们现有的用户数据的无缝迁移路径的方式,这不是真正为我们的选择。

FWIW: I know that Microsoft has introduced (yet another) membership and identity solution, but unless there's a way to use that with the existing Simple Membership tables, or a seamless migration path for all of our existing user data, that's not really an option for us.

我刚和我们的应用程序的当前Trunk的新鲜结帐再次尝试这样做。我使用Visual Studio 2012中,但除此之外,其次从MS的说明升级现有项目。更新到MVC后5 /网页API 2 / EF 6,应用程序启动的跑就好了。

I just tried this again with a fresh checkout of the current trunk of our app. I'm using Visual Studio 2012, but otherwise followed the instructions from MS for upgrading an existing project. After updating to MVC 5 / Web API 2 / EF 6, the app started up an ran just fine.

有分别在的web.config 没有明确的信任要求删除。我说从code <一个href=\"http://stackoverflow.com/questions/1064274/get-current-asp-net-trust-level-programmatically\">this问题以的Global.asax.cs ,并报告该应用程序是完全信任运行(在IIS防爆preSS,只是F5-ED从VS)。

There were no explicit trust requirements in the web.config to remove. I added the code from this question to Global.asax.cs, and it reports that the app is running with full trust (in IIS Express, just F5-ed from VS).

重新加入同一呼叫InitializeDatabaseConnection(),它开始具有完全相同的异常死亡。

Re-adding the same call to InitializeDatabaseConnection(), it starts dying with the exact same exception.

试图从周五@凯文的更新的解决方案,我发现它的作品。这真是奇怪,我加入这显然不相关的软件包将解决这些安全问题,甚至的更多的后,我删除了我的解决方案包陌生,它的继续工作的。

Trying the solution in @Kevin's update from Friday, I found that it works. It was really strange to me that adding this apparently unrelated package would solve these security issues, and even more strange after I removed the package from my solution, and it kept working.

在考虑发生了什么定睛一看,我意识到,为什么这种修复该问题的原因很简单: Microsoft.AspNet.WebHelpers 包有两个依赖关系正在加入到我的解决方案: Microsoft.AspNet.WebPages.Data Microsoft.AspNet.WebPages.WebData 微软移动WebMatrix的班进入新的软件包。

Taking a closer look at what was happening, I realized that the reason why this fixes the behavior is quite simple: the Microsoft.AspNet.WebHelpers package has two dependencies that were being added to my solution: Microsoft.AspNet.WebPages.Data and Microsoft.AspNet.WebPages.WebData. Microsoft has moved the WebMatrix classes into new packages.

所以添加的助手包解决了问题,不是因为任何它在做什么,而是因为这是造成破组件的更新版本添加,以我的解决方案。最初的不兼容的解决方案,那么,是的NuGet更新一切时,安装这些新的软件包:

So added the helpers package fixed the problem, not because of anything it was doing, but because it was causing updated versions of the broken assemblies to be added to my solution. The solution to the initial incompatibility, then, is to install these new packages when updating everything else from NuGet:

Install-Package Microsoft.AspNet.WebPages.WebData

更新(2015年5月13日)

它已经向我建议,你可能还需要手动安装第二个新包:

UPDATE (13 May 2015)

It has been suggested to me that you may also need to manually install the second new package:

Install-Package Microsoft.AspNet.WebPages.Data

此的不应该的是必要的,因为这个包是显式依赖第一以及的NuGet应该足够聪明,同时安装。但是如果你的an构建错误时,还是看不到的NuGet添加的依赖,它可以帮助你。

This should not be necessary, because this package is an explicit dependency of the first, and NuGet should be smart enough to install both. But if you get an error when building, or don't see NuGet add the dependency, it might help you.

推荐答案

WebMatrix的是MVC 5.

WebMatrix is compatible with MVC 5.

我所做的就是把一个空的MVC 5项目并使用 SimpleSecurity 结合WebMatrix中SimpleMembershipProvider进去,一个开源项目<一个href=\"http://kevin-junghans.blogspot.com/2013/03/decoupling-simplemembership-from-your.html\">decouples SimpleMembership从你的MVC应用程序。到目前为止,我可以创建数据库,种子它,登录和退出。我打算加入其它功能,以该参考应用,如电子邮件确认和各种测试。当我做了我将张贴在 SimpleSecurity项目

What I did was to take an empty MVC 5 project and incorporate WebMatrix SimpleMembershipProvider into it using SimpleSecurity, an open source project that decouples SimpleMembership from your MVC application. So far I am able to create the database, seed it, and log in and out. I plan on adding other features to this reference application, such as email confirmation and various tests. When I am done I will post the source code in the SimpleSecurity Project

如果我猜的话,你的问题可能与升级过程。你采取什么程序到你的MVC 4项目升级到MVC 5? <一href=\"http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2\">Did按照此过程?您正在使用哪种版本的WebMatrix的组件?您正在使用什么版本的Visual Studio?我使用WebMatrix的的版本2.0.0.0和Visual Studio 2013 RC。

If I had to guess, your problem may be with the upgrade process. What process did you take to upgrade your MVC 4 project to MVC 5? Did you follow this process? What version of the WebMatrix assemblies are you using? What version of Visual Studio are you using? I am using version 2.0.0.0 of WebMatrix and Visual Studio 2013 RC.

更新(2013年10月25日)

我继续我的实验沿着它打破了行添加SimpleMembership到MVC 5项目以及地方和我相同的结果@Sixten奥托。我没有测试增量为我添加的东西,但我怀疑,当我安装Web API组件可能发生。创建一个新的MVC项目5时,他们不是默认安装的。

I continued my experiment with adding SimpleMembership to an MVC 5 project and somewhere along the line it broke and I got the same results as @Sixten Otto. I did not test incrementally as I added things but I am suspicious it may have happened when I installed the Web API assemblies. They are not installed by default when creating a new MVC 5 project.

我做了错误的一些更多的研究,并在此QA题为来<一href=\"http://stackoverflow.com/questions/17926552/attempt-by-security-transparent-method-webmatrix-webdata-$p$papplicationstartcod\">Attempt通过安全透明的方法WebMatrix.WebData。preApplicationStart code.Start()'。这是一个古老的质量保证和原来升级MVC 3应用程序时,MVC 4,但最近人们的问候升级被添加答案MVC 5和答案的一个工作对我来说有人收到此相同的错误。 我的解决办法是安装的NuGet包的 Microsoft.AspNet.WebHelpers 安装此软件包一切正常后。

I did some more research on the error and came across this QA titled "Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'". This is an old QA and originally someone was getting this same error when upgrading an MVC 3 app to MVC 4. But recently people have been adding answers in regards to upgrading to MVC 5 and one of the answers worked for me. The solution for me was install the NuGet package Microsoft.AspNet.WebHelpers. After installing this package everything worked fine.

我的研究,迁移到新的ASP.NET身份的说明是,他们没有使用相同的密码哈希值,其中precludes老成员迁入由ASP.NET身份使用的数据库。 ASP.NET身份似乎是在现在实际磁通所以也许他们会拿出一个解决方案。

A note about my research into migrating to the new ASP.NET Identity is that they do not use the same password hash, which precludes moving old members into a database used by ASP.NET Identity. ASP.NET Identity seems to be in real flux right now so maybe they will come up with a solution for this.

更新(14年2月16日)

我错误地报道说,密码散列算法是SimpleMembership和ASP.NET的身份不同。我以为这种基于散列的口令进行目视检查,假设这只是哈希密码,这是在田间地头。进一步的研究后,我发现,SimpleMembership使用System.Web.Helpers.Crypto类散列密码,什么是存储在密码字段实际上是一个256位的子项和盐。有了这些信息我跑了一些测试,以验证身份ASP.NET可以验证由SimpleMembership生成的密码,并且它通过了。我试图找出使用哈希算法SimpleMembership这样我就可以在ASP.NET的身份密码散列器,让我把数据从一个网站SimpleMembership迁移到一个使用ASP.NET身份插头。原来它是没有必要的。 我说说密码哈希,以及如何将数据从SimpleMembership迁移到ASP.NET身份在这篇文章更多的细节。

I erroneously reported that the hash algorithm for passwords was different in SimpleMembership and ASP.NET Identity. I assumed this based on a visual inspection of the hashed passwords, assuming that it was just the hashed password that was in the fields. After further research I found that SimpleMembership uses the System.Web.Helpers.Crypto class for hashing the password and what is stored in the password field is actually a 256 bit subkey and the salt. With that information I ran some tests to validate that ASP.NET Identity can verify passwords that are generated by SimpleMembership, and it passed. I was trying to find out what hash algorithm SimpleMembership used so I could plug in a password hasher in ASP.NET Identity that would allow me to migrate data from a SimpleMembership webiste to one that used ASP.NET Identity. Turns out it is not necessary. I talk about the password hash and how to migrate the data from SimpleMembership to ASP.NET Identity in more detail in this article.

这篇关于是ASP.NET MVC 5与WebMatrix的SimpleMembershipProvider不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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