2016-11-15 56 views
4

我想在我的应用程序中使用隐藏元素的角色,并且这在我的开发环境中的Visual Studio Express中工作正常。但是,当我发布该网站并将其放入实时环境中时,现在出现无法连接到SQL Server实例的错误。asp.net角色管理器错误

它看起来像几个人评论说在这个岗位同样的事情: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> 
+0

你确定问题是因为角色提供者吗?看起来这个错误是因为在连接字符串中使用了Windows身份验证:“Integrated Security = True”。所以你应该首先在''下启用模拟''。看看[如何:使用Windows集成安全访问SQL Server](https://msdn.microsoft.com/en-us/library/bsz5788z.aspx) –

+0

@RezaAghaei有问题的应用程序在Internet上,而不是在Internet上一个内联网,但你可能会想到开发环境显然是内联网。我对创建Web应用程序非常新(这是我的第一个),所以更改web.config以使用Internet对我来说是新的。应用程序的用户只能登录到应用程序,他们没有与组织的任何其他关联,所以根本没有Windows帐户。如果我需要对web.config进行更改才能工作,那就是我需要知道如何去做的。 –

+0

您正在为DefaultRoleProvider使用* Windows身份验证*。这意味着执行应用程序的帐户(您的应用程序池标识或模拟用户)应该可以使用Windows身份验证访问数据库。否则,您应该将连接字符串更改为SQL Server身份验证。对于远程数据库,如果要使用Windows身份验证,则应具有可访问远程数据库的域用户帐户。对于本地数据库(与应用程序服务器计算机相同的机器),您应该有一个可访问数据库的本地用户帐户。 –

回答

4

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

尝试更改为User ID = userName; Password = passWord现在没有人可以登录到网站期间,因为“userName”的登录失败。知道这必须代表简单的东西,但不知道应该是什么。 –

+0

此外,列出的Web配置来自我的开发环境,实际站点上的连接字符串通过IP指向实时服务器,但它具有如上所示配置的集成安全性。 –

+0

检查SQL服务器的配置,看看它是否接受用户名/密码组合的?而且您的网站是在公司服务器内部托管的,因为如果不是集成安全性不是真正的选择。 – VDWWD

1

您的角色管理器部分看起来有点离奇。 组装令牌中的这个“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> 

我想,虽然Rolemanager使用“DefaultConne应用程序正在使用的连接“CS1”的连接ction

你有数据库联机”,这点到另一个数据库(‘ASPNET-cs1-20160511031253’):ASPNET-cs1-20160511031253 如果没有,你添加它,或添加CS1的ASPNET表和改变角色管理器指向DefaultConnection

的CS1数据库isntead
<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> 
+0

这实际上是从早期评论中恢复到其原始值的东西。应用程序正在连接并使用SQL服务器正常,,,直到启用角色管理器角色。那么它有一个问题,但只有角色管理器。奇怪的角色也被用来隐藏/显示菜单项而不使用角色管理器。 –

+0

好吧,我编辑了答案,这个问题可能是你使用的是错误的连接(而不是DefaultConnection CS1),一看便知底部 –

1

基于角色的认证是所有认证用户在网站上 - 而不是你的SQL Server连接,所以我就从这个问题删除并发症。你的问题是你无法连接到SQL Server - 简单而简单。

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

+0

这就是我真的不明白。该应用程序正在工作,显然是读取和写入SQL数据库,,,直到我启用角色管理器。我不知道这是什么独特的,为什么它不能连接。 –

+0

应当把它给我,启用“rolemanager”,然后添加“综合安全” - 这需要当前用户标识,并使用该登录到SQL服务器 - 可能会导致SQL Server登录突破。虽然我不理解内部 - 你实际上已经改变了ASP.net/IIS中的用户。我建议向SQL服务器添加用户名和密码,并忘记此生产/实时主机上的“集成安全性”。 –