c# - asp.net 角色管理器错误

标签 c# asp.net

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

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

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

如果我在 web.config 中删除 roleManager enabled="true"代码行,站点将连接,直到我到达我的代码看起来隐藏控件的位置,然后关于 rolemanager 未启用的错误。

这是我的 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>

最佳答案

我不认为服务器名为 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"/>

关于c# - asp.net 角色管理器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40616640/

相关文章:

c# - 如何在 C# 文件中创建 List<T> 实例

c# - 如何从数组中找到第 n 个重复项

C# Rest API 返回动态对象

c# - Ajax 幻灯片放映扩展器不起作用

asp.net - 错误 : Must declare the scalar variable "@data"

c# - 在 C# 中使用位图对象查找图像格式

c# - 您如何通过单击 asp.net 中的图像按钮流式传输 zip 文件?

带有代码隐藏值 "Source:"的 jQuery 组合框

.net - 在共享主机上加密 web.config

javascript - 将输入键绑定(bind)到 asp 网络链接按钮转发器