【问题标题】:Custom user authentication ASP.net MVC not working on server自定义用户身份验证 ASP.net MVC 在服务器上不起作用
【发布时间】:2019-03-11 01:22:07
【问题描述】:

我在一个项目中使用了一个教程,但遇到了用户角色在服务器上没有更新的问题。在本地一切正常,但是当发布到 Azure 服务器时,角色不会更新。我利用了本教程: Custom-Authentication-asp-net-MVC

这是我的 web.config:

<membership defaultProvider="CustomMembership">
  <providers>
    <clear />
    <add name="CustomMembership" type="YouAndMeRealty.Authentication.CustomMembership" />
  </providers>
</membership>
<roleManager defaultProvider="CustomRole" enabled="true" >
  <providers>
    <clear />
    <add name="CustomRole" type="YouAndMeRealty.Authentication.CustomRoles" />
  </providers>
</roleManager>

我在网上看到可能是我的 web.config 中遗漏了一些东西,但我在用户管理方面非常缺乏经验。请任何人帮忙。

【问题讨论】:

    标签: c# asp.net asp.net-mvc authentication


    【解决方案1】:
        <connectionStrings>  
        <add name="AuthenticationDB" connectionString=" Data Source=.;Initial Catalog=CustomAuthenticationDB;Integrated Security=True" providerName="System.Data.SqlClient" />  
      </connectionStrings>  
    

    您确定您的连接字符串是正确的吗?请与我们分享您的连接字符串。

    这可能是因为这种用法

      <providers>
        <clear />
        <add name="CustomRole" type="YouAndMeRealty.Authentication.CustomRoles" />
      </providers>
    

    改成:

     <providers>
        <clear />
        <add name="CustomRole" type="YouAndMeRealty.Authentication.CustomRole" />
      </providers>
    

    【讨论】:

    • 我完全确定连接字符串是正确的,因为它可以正确检索用户并允许我登录,并且我创建的角色管理器称为 CustomRoles,所以这不是问题。不过还是谢谢你的建议。
    【解决方案2】:

    我找到了我在角色管理器上缺少 applicationname 属性的答案:

    <providers>
    <clear />
    <add name="CustomRole" type="YouAndMeRealty.Authentication.CustomRole" />
    

    应该是

    <providers>
        <clear />
        <add name="CustomRole" type="YouAndMeRealty.Authentication.CustomRoles" applicationName="sitename.azurewebsites.net"/>
      </providers>
    

    真正让我感到困惑的是添加 .azurewebsites.net,因为我曾尝试过此修复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多