我为需要基本密码保护的客户设置了一个简单的预览网站。我正在使用表单例份验证以及 web.config
中指定的凭据。
Everything works fine on my box (famous last words)
但是,当我部署到运行 Win2008 的生产网站时,身份验证代码会尝试打开 SQL Server 数据库(我在 web.config
中没有引用任何 SQL)。如何禁用此行为,以便基于我在 web.config
中输入的凭据进行身份验证?
事件日志中出现异常
无法连接到 SQL Server 数据库。
在System.Web.Management.SqlServices.GetSqlConnection(字符串服务器,字符串用户,字符串密码, bool 信任,字符串连接字符串)
在 System.Web.Management.SqlServices.SetupApplicationServices(字符串服务器、字符串用户、字符串密码、 bool 信任、字符串连接字符串、字符串数据库、字符串 dbFileName、SqlFeatures 功能、 bool 安装)
在System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(字符串fullFileName,字符串dataDir,字符串connectionString)
在 System.Web.DataAccess.SqlConnectionHelper.EnsureSqlExpressDBFile(字符串连接字符串)
...
在System.Data.SqlClient.SqlConnection.Open()在System.Web.Management.SqlServices.GetSqlConnection(字符串服务器,字符串用户,字符串密码, bool 信任,字符串连接字符串)
http://my.site.com/Login.aspx?ReturnUrl=/
web.config(相关部分)
<system.web>
<compilation targetFramework="4.0" />
<authentication mode="Forms">
<forms name="appNameAuth" path="/" loginUrl="Login.aspx" protection="All" timeout="30">
<credentials passwordFormat="SHA1">
<user name="me" password="SHA1OfMyPassword" />
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
<allow users="me" />
</authorization>
</system.web>
最佳答案
事实证明,在生产计算机上,SQL 成员资格提供程序是在 machine.config 中定义的。我认为运营团队没有对默认的 Windows 2008 安装进行任何更改,因此该平台的情况可能通常如此。
要删除对在更高级别定义的任何 SQL 提供程序的引用,请在 web.config 中包含以下内容
<membership>
<providers>
<clear />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
<profile>
<providers>
<clear />
</providers>
</profile>
关于asp.net - 禁用 SQL 成员资格提供程序(ASP.Net 表单例份验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5481132/