繁体   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