簡體   English   中英

錯誤:26-托管到Web服務器后定位服務器/實例時出錯

[英]Error: 26 - Error Locating Server/Instance Specified after hosting to a web server

我使用Asp.Net MVC C#開發了網站,並且在Visual Studio中在我的PC上本地一切正常。 將網站托管到服務器后,出現錯誤:26-查找指定的服務器/實例時出錯 按下登錄按鈕后,當我嘗試登錄網站時會顯示錯誤。 我認為問題在於在App_Data文件夾中自動創建了身份驗證數據庫ASPNETDB.mdf以及該數據庫的連接字符串 我之前一直在搜索並嘗試其他已經發布的解決方案,但仍然無法解決該錯誤。我嘗試了不同的解決方案來解決web.config中的問題,但未成功。

我正在尋找的解決方案是在配置ASP.NET Identity成員資格系統中的某處,該系統在我的PC上本地運行良好,而不是在上傳之后運行。

我已經有一個數據庫,並且該數據庫具有一個連接字符串(BicycleWorldShop2)。 我應該將ASPNETDB.mdf作為第二個數據庫發布,並在web.config文件中添加第二個連接字符串嗎? 如何正確配置成員資格?

這是我的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=301880 --> <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" /> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.6.1" /> <httpRuntime targetFramework="4.6.1" /> <globalization culture="en-IN" /> <authentication mode="Forms"> <forms loginUrl="~/Accounts/LogOn" timeout="2880" /> </authentication> <customErrors mode="Off" /> <membership> <providers> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/> </providers> </membership> <profile> <providers> <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </providers> </profile> <roleManager enabled="true"> <providers> <clear/> <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </providers> </roleManager> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> </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> <connectionStrings> <add name="BicycleWorldShop2" connectionString="Data Source=WW-PC\\SqlExpress;Initial Catalog=BicycleWorldShop;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> 
我應該更改我的代碼嗎?

有人解決這個問題嗎?

請尋求任何幫助,我會浪費大量時間來嘗試解決此錯誤!

錯誤: 在此處輸入圖片說明

我建議備份ASPNETDB.mdf並將其還原為托管服務器上的單獨數據庫。 然后在<connectionStrings> web.config部分下創建第二個connectionstring。

最后,更新成員資格,概要文件和roleManager提供程序上的connectionstringName屬性。

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SecondConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>

將ASPNETDB對象添加到同一數據庫的替代方法

在您的計算機上,在運行命令中鍵入%WINDIR%\\Microsoft.Net\\Framework\\ ,然后轉到v4.0 ...文件夾。 在此文件夾中,您將找到用於創建成員資格,配置文件和角色架構的T-SQL腳本文件。 您將需要在托管服務提供商數據庫上執行腳本。

您將需要首先執行InstallCommon.sql以創建公用表。 然后,執行以下腳本。

  1. InstallMembership.sql
  2. InstallProfile.SQL
  3. InstallRoles.sql

注意:上述所有腳本均假定您具有名為aspnetdb數據庫,因此您將需要在文本編輯器中打開每個sql文件,然后更改以下代碼行以匹配您的數據庫名稱:

SET @dbname = N'aspnetdb'
USE [aspnetdb]

PS ,您真的需要AspNetWindowsTokenRoleProvider嗎? 另外,在成員資格和個人資料提供者部分中添加<clear/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM