禁用SQL Membership Provider(ASP.Net表单身份验证)

3

我为一个需要基本密码保护的客户设置了一个简单的预览网站。我正在使用在web.config中指定的凭据进行表单身份验证。

一切都在我的电脑上运行良好(最后的话)

然而,当我部署到运行Win2008的生产网站时,身份验证代码会尝试打开SQL Server数据库(在web.config中没有任何SQL的引用)。我如何禁用此行为,以便身份验证基于我在web.config中输入的凭据?

事件日志中的异常

无法连接到SQL Server数据库。 在System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) 在System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) 在System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) 在System.Web.DataAccess.SqlConnectionHelper.EnsureSqlExpressDBFile(String connectionString) ... 在System.Data.SqlClient.SqlConnection.Open() at System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString)
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>
1个回答

11

事实证明,在生产机器上,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>

谢谢。这个回答解决了我的问题,还有这里概述的“enableSimpleMembership”条目:http://stackoverflow.com/questions/12116736/aspnet-role-provider-kicking-in-and-it-shouldnt-be - Josh
1
以上链接(12116736)中此解决方案的缺失部分是:<add key="enableSimpleMembership" value="false" /> 在<appSettings>部分。 - Nigel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接