Asp.net角色管理器错误
本文关键字:错误 管理器 角色 net Asp | 更新日期: 2023-09-27 18:18:14
我试图使用角色来隐藏我的应用程序中的元素,这在我的开发环境中的Visual Studio Express中工作得很好。但是,当我发布站点并将其放入活动环境中时,我现在得到一个关于无法连接到sql server实例的错误。
似乎有几个人在这篇文章中评论了同样的事情:角色管理器功能还没有启用
但是我不知道如何解决这个问题。
如果我拿出的roleManager enabled="true"行代码在web。配置网站将连接,直到我得到的地方,我有代码,看起来隐藏一个控件,然后关于rolemanager未启用的错误。
这是我的网。配置文件,我不知道如何让这个正确工作。对很多web编程来说还是个新手:
<?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='"Web'" /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"/>
基于角色的身份验证是关于对网站上的用户进行身份验证-而不是关于您的SQL Server连接,所以我会从这个问题中消除复杂性。你的问题是你不能连接到SQL Server -简单明了。
要解决这个问题,请检查您正在获得的特定错误消息"无法连接到SQL Server"-连接被拒绝吗?(这意味着SQL Server不监听TCP/1433,只使用套接字或临时文件)。很可能是密码不正确。在您的远程服务器上,尝试使用RDP(远程桌面)来验证您可以使用您进入的帐户的用户名和密码登录到SQL server。最有可能的是,您应该在远程服务器上使用简单的用户名和密码,而不是在开发过程中使用集成安全性。
您的角色管理器部分看起来有点奇怪。汇编令牌中的"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使用指向另一个数据库("aspnet-cs1-20160511031253")的"DefaultConnection"
您是否有在线数据库: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>