【发布时间】:2018-12-24 18:04:51
【问题描述】:
我使用 Asp.Net MVC C# 开发了网站,并且在我的电脑上的 Visual Studio 中一切正常。将网站托管到服务器后,我得到错误:26 - 错误定位服务器/指定实例。按下登录按钮后,当我尝试登录网站时出现错误。 我认为问题在于 App_Data 文件夹中自动创建的身份验证数据库 ASPNETDB.mdf 以及该数据库的 连接字符串。 我之前一直在搜索并尝试不同的已发布解决方案,但仍然无法解决错误。我在 web.config 中尝试了不同的解决方案来解决该问题,但未成功。
我正在寻找的解决方案是配置我的 ASP.NET 身份会员系统,该系统在我的电脑上本地运行良好,而不是在上传后。
我已经有一个数据库,其中包含一个与该数据库 (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>
有没有人可以解决这个问题?
请帮忙,我浪费了很多时间来尝试解决这个错误!
【问题讨论】:
-
您是否在该 VM 上安装了 SqlServer?
-
我将网站发布到 smarterasp.net 主机。从已发布的数据库 BicycleWorldShop2 中读取数据可以正常工作,但问题仅在于身份验证。用户数据存储在 ASPNETDB.mdf 数据库中,该数据库是在 Visual Studio 中自动创建的,具有成员身份。
-
您的会员提供者依赖于
connectionStringName="LocalSqlServer",这似乎不会导致有效实例。在您的 web.config 中添加一个额外的连接字符串,该字符串指向包含成员资格的目录。 -
首先将
Data Source=WW-PC\SqlExpress改为Data Source=localhost
标签: c# asp.net asp.net-mvc hosting publish