2016-11-15 54 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服務器添加用戶名和密碼,並忘記此生產/實時主機上的「集成安全性」。 –