我的家用计算机运行 Visual Studio 2012 和 SQL Server 2008 R2。该网站一直在我运行 VWD10/SQLEXPRESS 的工作计算机上运行。我可以访问和运行除我的 admin.aspx 页面之外的所有页面。
登录成功后,点击我的Admin,aspx页面,里面只有一个loginview控件,后面没有代码。该网站挂起然后我收到错误:
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)
我删除了 loginview 控件,然后再试一次。页面没有代码和控件正确加载。我的下一个尝试是添加到页面加载:
string str = Roles.GetRolesForUser("Admin").First();
这导致了同样的错误,我已经将我的页面恢复为没有代码和一个 loginview 控件。
我不确定为什么 Role 类不能访问数据库,但 member 类可以。
这是我的 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>
<location path="~/Admin.aspx">
<system.web>
<authorization>
<allow roles="Admin,Maintainer,Manager,Supervisor" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Admin_Machines.aspx">
<system.web>
<authorization>
<allow roles="Admin,Maintainer,Manager" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Admin_Workcenters.aspx">
<system.web>
<authorization>
<allow roles="Admin,Maintainer,Manager" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Admin_Procedure.aspx">
<system.web>
<authorization>
<allow roles="Admin,Maintainer,Manager,Supervisor" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Admin_Users.aspx">
<system.web>
<authorization>
<allow roles="Admin,Manager" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Admin_Section.aspx">
<system.web>
<authorization>
<allow roles="Admin,Maintainer,Manager" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Admin_Tensile.aspx">
<system.web>
<authorization>
<allow roles="Admin,Maintainer,Manager" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="~/Procedures">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<membership defaultProvider="myProvider">
<providers>
<add name="myProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="userdb" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/"
requiresUniqueEmail="True" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
</providers>
</membership>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
</buildProviders>
</compilation>
</system.web>
<connectionStrings>
<!--Home/School connection(SQLSERVER 2008 R2-->
<add name="QualityEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=QUALITY.MDF;user id=sa;password=****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="userdb" connectionString="Data Source=.;Initial Catalog=ASPNETDB;uid=sa;Password=****" />
<!--Work Connection(SQLEXPRESS)-->
<!--<add name="QualityEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Quality.mdf;integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />-->
<!--<add name="userdb" connectionString="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ASPNETDB.mdf;integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;" />-->
</connectionStrings>
</configuration>