你如何延长ASP.NET MVC4的SimpleMembership认证 [英] How do you extend the SimpleMembership authentication in ASP.NET MVC4

查看:131
本文介绍了你如何延长ASP.NET MVC4的SimpleMembership认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了几个ASP.NET MVC 1和2个站点。不知怎的,我成功地跳过V3。
现在我创建一个新的ASP.NET MVC 4个网站,我看到了所有的会员的东西已经完全改变了。

起初,我很高兴。它看起来很容易安装和使用与互联网项目模板附带的所有类和看法我需要开始。

不幸的是,我现在完全被卡住。我需要延长code的认证用户。基本上,我需要一些用户对Web服务和其他用户对本地数据库进行身份验证。这两种类型的用户将具有存储在本地数据库中信息的内容

我的问题是,我无法找到延长SimpleMembership任何方式。

在旧的会员提供者模型,我会采取刺伤从SqlMembership继承和压倒一切的ValidateUser()和调用基类或调用Web服务。

我也尝试做这样的事情,我的建立在我的项目的一类,从SimpleMembership inherites,然后将其配置为在web.config中的默认成员资格提供程序,但只是给我的错误

 分析器错误信息:此方法不能在应用程序的pre-启动初始化阶段被调用。第32行:其中,会员defaultProvider =ssund>
第33行:LT;供应商>
34号线:其中;加入NAME =ssundTYPE =Ssund.Web.Providers.SsundSimpleMembershipProvider/>
第35行:LT; /供应商>
36号线:LT; /会员>


解决方案

您可以扩展 SimpleMembershipProvider ,但它不是一个愉快的经历,由于不寻常的和限制性的方式提供商初始化。

虽然提供者通过调用初始化 WebSecurity.InitializeDatabaseConnection ,通过设置提供商的Web.Config 明确是一样有效。只要它们从 SimpleMembershipProvider 延长他们会正确初始化过程中进行配置。

在事实上你可能只是实现自己的 ExtendedMembershipProvider WebSecurity API的使用,而不是叫 WebSecurity.InitializeDatabaseConnection 在所有(这仅适用于 SimpleMembershipProvider 基于实现)。不足之处是这是一个大量的工作,从头开始构建这个。

您都拿到很可能与供应商造成的相互作用错误早期的管道,可能是因为你在做供应商的初始化程序内的东西。

请参阅 SimpleMembershipProvider VS的MembershipProvider 了解的 SimpleMembershipProvider 之间的差异和的MembershipProvider 。而看看 BetterMembership.Net 以延长<$ C的例子$ C> SimpleMembershipProvider 。

I've done several ASP.NET MVC 1 and 2 sites. Somehow I managed to skip v3. I'm now creating a new ASP.NET MVC 4 site and I see that all the Membership stuff has changed completely.

At first I was happy. It looked easy to setup and use and the Internet project template came with all the classes and views I needed to get started.

Unfortunately, I'm now completely stuck. I need extend the code that authenticates a user. Basically, I need to authenticate some users against a web service and other users against the local database. Both types of users will have profile data stored in the local database.

My problem is that I can't find any way extending SimpleMembership.

Under the old Membership provider model, I would have taken a stab at inheriting from SqlMembership and overriding ValidateUser() and calling the base class or calling the web service.

I did try doing something like that my creating a class in my project that inherites from SimpleMembership and then configuring it as the default membership provider in web.config, but that just gave me the error

Parser Error Message: This method cannot be called during the application's pre-start initialization phase.

Line 32:     <membership defaultProvider="ssund">
Line 33:       <providers>
Line 34:         <add name="ssund" type="Ssund.Web.Providers.SsundSimpleMembershipProvider"/>
Line 35:       </providers>
Line 36:     </membership>

解决方案

You can extend SimpleMembershipProvider but it's not a pleasant experience due to the unusual and restrictive way the providers are initialized.

Although the providers are initialized via a call to WebSecurity.InitializeDatabaseConnection, setting the providers via the Web.Config explicitly is just as valid. Provided they extend from SimpleMembershipProvider they will be configured correctly during initialization.

In fact you could just implement your own ExtendedMembershipProvider for use with WebSecurity APIs, and not call WebSecurity.InitializeDatabaseConnection at all (it's only for SimpleMembershipProvider based implementations). The downside is that's is a lot of work to build this from scratch.

The error you were getting was probably caused by interaction with the providers to early in the pipeline, possibly because you were doing something within the Initialize routine of the provider.

See SimpleMembershipProvider vs MembershipProvider for more information of the differences between SimpleMembershipProvider and MembershipProvider. And take a look at BetterMembership.Net for an example of extending the SimpleMembershipProvider.

这篇关于你如何延长ASP.NET MVC4的SimpleMembership认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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