我是ASP.net的新手,只学习教程。这个特殊的问题一直让我头疼,我在VS 2010中开发了一个网站,使用Asp.Net登录控件提供的ASPNETDB SQL服务器数据库来创建用户和角色。还添加了一些表,在我完成后使用"发布到提供程序"功能生成脚本(ASPNETDB.MDF.sql)。我使用此脚本生成数据库和表-sql Server 2008 R2 management Studio,并像这样修改web.config-
<!--Connection String-->
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Server=AkumJamir-PCSQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="con" connectionString="Server=AkumJamir-PCSQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True"/>
<add name="ConnectionString" connectionString="Server=AkumJamir-PCSQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<roleManager enabled="true">
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add connectionStringName="ConnectionString" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider,System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove name="AspNetWindowsTokenProvider"/>
</providers>
</roleManager>
<membership>
<providers>
<remove name="AspNetMembershipProvider"/>
<add connectionStringName="ConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphaNumericCharacters="1" passwordAttemptWindow="5" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider,System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
<webParts>
<personalization defaultProvider="AspNetSqlPersonalizationProvider">
<providers>
<remove name="AspNetSqlPersonalizationProvider"/>
<add name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.Webparts.SqlPersonalizationProvider"
connectionStringname="ConnectionString" applicationName="/"/>
</providers>
</personalization>
</webParts>
现在的问题是,这在我的开发机器上有效,但在我们的暂存服务器上,每当我试图浏览到一些页面时,它都不会连接到数据库,在那里我有一些数据要从数据库中显示,登录页面也不起作用。connectionString在服务器中看起来像这样:
<!--Connection String-->
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Driver={SQL Native Client};Server=WIN-K16NMM4128C;Initial Catalog=ASPNETDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="con" connectionString="Server=WIN-K16NMM4128C;Initial Catalog=ASPNETDB;Integrated Security=True"/>
<add name="ConnectionString" connectionString="Data Source=WIN-K16NMM4128CSqlServer2008;Initial Catalog=ASPNETDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
我正在吞噬我的大脑,我已经看完了涵盖的主题,,,,谢谢你的建议。。。
我也面临同样的问题。我刚刚在IIS管理器中启用了ASP/Authentication,并将"基本身份验证"设置为true。它现在正在工作。
您在连接字符串中使用集成安全性。将其配置为使用sql身份验证。类似这样的东西:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;