一个MVC网站,有多个白标签。如何使用MembershipProvider? [英] One MVC Website with multiple whitelabels. How to use the MembershipProvider?

查看:128
本文介绍了一个MVC网站,有多个白标签。如何使用MembershipProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我目前正在使用MVC4网站,该网站使用标准的MembershipProvider来启用登录。该网站有多个视图使用相同的MVC引擎,这样我们有1个网站就像2个不同的网站,而唯一不同的是设计和URL。使用自定义MVC视图引擎一切都很好。



现在我的问题是,当我在whitelabel#1上创建一个帐户时,我也可以登录whitelabel# 2使用相同的凭据。这是因为两个网站都使用相同的MVC引擎,因此它们使用相同的MembershipProvider / ApplicationID。



这是错的。



两个网站都应该有自己的MembershipProvider,所以你不能使用相同的凭据。



现在我已经对这个问题进行了一些讨论,并找到了一个解决方案,即不使用单身MembershipProvider并自行实现。但是我不能使用智能MVC安全解决方案,比如在控制器上使用[Authorize]标签。



有没有人有这方面的解决方案?



Willem

Hi,

I''m currently working on a MVC4 Website which uses the standard MembershipProvider to enable login''s. The website has multiple view''s which use the same MVC engine, this way we have 1 website that acts like 2 different websites, while the only thing that is different is the design and URL. This all works great using a custom MVC View-engine.

Now for my problem, when I create a account on whitelabel #1, I can also login on whitelabel #2 using the same credentials. This is because both websites use the same MVC Engine, so they use the same MembershipProvider / ApplicationID.

This is wrong.

Both websites should have their own MembershipProvider, so you cannot login using the same credentials.

Now I''ve already goolged a little on this subject and found a solution by not using the singleton MembershipProvider and instanciate it myself. But then I cannot use the smart MVC security solutions like using the [Authorize] tag on controllers.

Does anyone have a solution for this?

Willem

推荐答案

如果你需要使用不同的会员提供者,那么你可能会发现你需要在IIS中设置两个独立的Web应用程序。您应该在两个应用程序之间编写任何公共代码,并且只引用每个应用程序的代码。这不仅可以解决您的身份验证问题,还可以简化每个应用程序的维护和灵活性。
If you need to use a different membership provider, then you will probably find that you''ll need to setup two independent Web Applications in IIS. You should library any common code between the two applications and just reference that code from each application. This will not only solve your authentication issues, but will also simplify the maintenance and flexibility of each application.


添加此类:

Add this class:
public class CustomMembershipProvider : SqlMembershipProvider
{
    public override string ApplicationName
    {
        get
        {
            return ConfigHelper.DomainConfig.Name; // My own applicationname according to the URL.
        }
        set
        {
        }
    }
}



然后替换web.config中的成员资格节点:


Then replace the membership node in the web.config:

<membership defaultprovider="CustomMembershipProvider">
  <providers>
    <clear />
    <add name="CustomMembershipProvider" type="CustomMembershipProvider">
         connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"
         requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5"
         minRequiredPasswordLength="6"
         minRequiredNonalphanumericCharacters="0"
         passwordAttemptWindow="10"
         applicationName="/" />
  </add></providers>
</membership>


这篇关于一个MVC网站,有多个白标签。如何使用MembershipProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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