【问题标题】:asp.net role manager errorasp.net 角色管理器错误
【发布时间】:2016-11-15 18:00:18
【问题描述】:

我正在尝试使用角色来隐藏我的应用程序中的元素,这在我的开发环境中的 Visual Studio Express 中运行良好。但是,当我发布站点并放入实时环境时,我现在收到一个关于无法连接到 sql server 实例的错误。

好像有几个人在这篇文章中评论了同样的事情:The Role Manager feature has not been enabled

但我没有看到该评论的解决方案。

如果我在 web.config 中取出 roleManager enabled="true" 代码行,该站点将连接,直到我到达有隐藏控件的代码的位置,然后出现有关角色管理器未启用的错误。

这是我的 web.config 文件,我不知道如何让它正常工作。仍然是很多网络编程的菜鸟:

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=S192-169-136-24\ABPATH;Initial Catalog=aspnet-cs1-20160511031253;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="CS1" connectionString="Data Source=S192-169-136-24\ABPATH;Initial Catalog=CS1;Integrated Security=True" providerName="System.Data.SqlClient" />
 </connectionStrings>
 <system.web>
 <authentication mode="None" />
 <compilation targetFramework="4.5.2" />
 <httpRuntime maxRequestLength="2097151" targetFramework="4.5.2" requestValidationMode="2.0" requestPathInvalidCharacters="" />
  <pages validateRequest="false">
  <namespaces>
    <add namespace="System.Web.Optimization" />
    <add namespace="Microsoft.AspNet.Identity" />
  </namespaces>
  <controls>
    <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
  </controls>
</pages>
<membership>
  <providers>
    <!--
      ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
    -->
    <clear />
  </providers>
</membership>
<profile>
  <providers>
    <!--
      ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
    -->
    <clear />
  </providers>
</profile>
<roleManager defaultProvider="DefaultConnection" enabled="true">
<providers>
   <add name="DefaultConnection" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=NUMBER" connectionStringName="DefaultConnection" applicationName="/" />
 </providers>
</roleManager>
<!--
        If you are deploying to a cloud environment that has multiple web server instances,
        you should change session state mode from "InProc" to "Custom". In addition,
        change the connection string named "DefaultConnection" to connect to an instance
        of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
  -->
  <sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
  </providers>
 </sessionState>
  <httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
 </httpModules>
 </system.web>
 <system.webServer>
 <rewrite>
    <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions> 
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
  </rule>   
    </rules>
  </rewrite>
  <modules>
  <remove name="FormsAuthentication" />
  <remove name="ApplicationInsightsWebTracking" />
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
    <httpRedirect enabled="false" destination="https://www.pathcertlink.com/" exactDestination="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
    </dependentAssembly>
    </assemblyBinding>
   </runtime>
 <entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
   <providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
   </providers>
  </entityFramework>
  <system.codedom>
 <compilers>
  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
  </compilers>
 </system.codedom>
 </configuration>

【问题讨论】:

  • 你确定问题是因为角色提供者吗?似乎错误是因为在连接字符串中使用了 Windows 身份验证:Integrated Security=True。所以你应该首先在&lt;system.web&gt;下启用模拟&lt;identity impersonate="true" /&gt;。看看How to: Access SQL Server Using Windows Integrated Security
  • @RezaAghaei 有问题的应用程序在 Internet 上,而不是 Intranet,但您可能会遇到一些问题,因为开发环境显然是 Intranet。我对创建 Web 应用程序非常陌生(这是我的第一个),因此更改 web.config 以使用 Internet 对我来说是新的。应用程序的用户只登录应用程序,他们与组织没有任何其他关联,因此根本没有 Windows 帐户。如果我需要对 web.config 进行更改才能正常工作,那就是我需要知道该怎么做。
  • 您正在为DefaultRoleProvider 使用Windows 身份验证。这意味着执行您的应用程序的帐户(您的应用程序池标识或模拟用户)应该可以使用 Windows 身份验证访问数据库。否则,您应该将连接字符串更改为 SQL Server 身份验证。对于远程数据库,如果要使用 Windows 身份验证,您应该有一个可以访问远程数据库的域用户帐户。对于本地数据库(与应用服务器机器相同的机器),您应该有一个访问数据库的本地用户帐户。
  • 这些是基本问题:1) 您是使用本地数据库(SQL 安装在同一台机器上)还是远程数据库(SQL Server 安装在不同的机器上) ? 2) 应用服务器(和数据库服务器)是否加入了域? 3) 您是否有域用户名/密码或 SQL Server 用户名/密码来连接数据库? 4) 您的应用程序中的身份验证机制是什么?您使用表单身份验证或 Windows 身份验证或其他方式吗?

标签: c# asp.net


【解决方案1】:

我不认为服务器叫LAPTOP-168YQ32

您可能需要将其更改为 localhost 或托管服务提供商提供的 IP 地址。我也不认为它会使用集成安全性,但需要用户名/密码组合。

连接字符串应如下所示。

<add name="DefaultConnection" connectionString="Data Source=192.168.0.101;Initial Catalog=aspnet-cs1-20160511031253;User ID=userName;Password=passWord" providerName="System.Data.SqlClient"/>

【讨论】:

  • 尝试更改用户 ID=userName;Password=passWord 现在没有人可以登录站点,因为“userName”登录失败。知道这一定代表简单的东西,但不知道应该是什么。
  • 此外,列出的 Web 配置来自我的开发环境,实时站点上的连接字符串确实通过 IP 指向实时服务器,但它确实具有如上所示配置的集成安全性。
  • 检查 SQL 服务器的配置,看它是否接受用户名/密码组合?并且您的网站是否在公司服务器内部托管,因为如果没有集成安全性,则不是一个真正的选择。
【解决方案2】:

基于角色的身份验证是关于对网站上的用户进行身份验证 - 而不是关于您的 SQL Server 连接,所以我会从这个问题中消除这个复杂性。您的问题是您无法连接到 SQL Server - 简单明了。

要解决此问题,请检查您收到的“无法连接到 SQL Server”的特定错误消息 - 连接是否被拒绝? (这意味着 SQL Server 没有侦听 TCP/1433 并且仅使用套接字或临时文件)。很可能,密码不正确。在您的远程服务器上,尝试使用 RDP(远程桌面)来验证您是否可以使用您登录的帐户的用户名和密码登录 SQL Server。最有可能的是,您应该在远程服务器上使用简单的用户名和密码,而不是使用通常在开发中完成的集成安全性。

【讨论】:

  • 那是我真正不明白的。该应用程序正在工作并且显然正在读取和写入 SQL 数据库,直到我启用角色管理器。我不知道这有什么独特之处以及为什么它无法连接。
  • 启用“rolemanager”,然后添加“Integrated Security”(采用当前用户 ID 并使用该用户 ID 登录 SQL Server)对我来说确实有意义,这可能会导致 SQL Server 登录中断。虽然我不了解内部结构 - 实际上您已经在 ASP.net/IIS 中更改了用户。我建议将用户名和密码添加到 SQL 服务器,并忘记此生产/实时主机上的“集成安全性”。
【解决方案3】:

您的角色管理器部分看起来有点奇怪。 程序集标记中的这个“NUMBER”是什么?

另外,可能是一个细节,此时值得尝试,为角色管理器指定一个不同于“DefaultConnection”的名称,因为它也是连接的名称

试试这个:

<roleManager defaultProvider="DefaultRoleProvider">
  <providers>
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
  </providers>
</roleManager>

我还看到你有 2 个连接

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=S192-169-136-24\ABPATH;Initial Catalog=aspnet-cs1-20160511031253;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="CS1" connectionString="Data Source=S192-169-136-24\ABPATH;Initial Catalog=CS1;Integrated Security=True" providerName="System.Data.SqlClient" />
 </connectionStrings>

我猜您的应用程序正在使用连接“CS1”,而 Rolemanager 使用指向另一个数据库的“DefaultConnection”(“aspnet-cs1-20160511031253”)

你有那个在线数据库吗:aspnet-cs1-20160511031253 如果没有,则添加它,或者在 CS1 中添加 aspnet 表并将角色管理器更改为指向 CS1 数据库而不是 DefaultConnection

<roleManager defaultProvider="DefaultRoleProvider">
  <providers>
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="CS1" applicationName="/"/>
  </providers>
</roleManager>

【讨论】:

  • 这实际上是来自早期评论的内容,已恢复其原始值。应用程序正在连接和使用 SQL 服务器,直到启用角色管理器角色。那么它有一个问题,但仅限于角色管理器。奇怪的角色也用于隐藏/显示其他地方的菜单项,而无需使用角色管理器。
  • 好的,我编辑了答案,问题可能是您使用了错误的连接(默认连接而不是 CS1),请参阅答案底部
猜你喜欢
  • 2012-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
相关资源
最近更新 更多