【问题标题】:Windows authentication - MVC 2 ASP.NetWindows 身份验证 - MVC 2 ASP.Net
【发布时间】:2010-06-14 15:58:08
【问题描述】:

将我的应用程序转移到 Windows 身份验证时遇到实际问题。

sql 错误消息与在 aspnetdb.mdf 文件中创建的问题有关。

我想知道是连接字符串有问题还是 web.config 的其他元素有问题

我在 IIS 中设置了 Windows 身份验证。

web.config:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|ASPNETDB.MDF;User Instance=true"
      providerName="System.Data.SqlClient" />
    <add name="orderbaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\orderbase.mdf;Integrated Security=True;User Instance=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="windows">

    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="true">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/"
          name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
          type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

还有 sql 错误:

无法打开物理文件 “C:\inetpub\wwwroot\Ordering\App_Data\ASPNETDB_log.ldf”。 操作系统错误 5:“5(未能 检索此错误的文本。原因: 15105)"。遇到创建文件 操作系统错误 5(未能 检索此错误的文本。原因: 15105),而试图打开或 创建物理文件 'C:\inetpub\wwwroot\Ordering\App_Data\ASPNETDB_log.ldf'。 无法打开新数据库 'C:\INETPUB\WWWROOT\ORDERING\APP_DATA\ASPNETDB.MDF'。 CREATE DATABASE 已中止。一次尝试 附加一个自动命名的数据库 文件 C:\inetpub\wwwroot\Ordering\App_Data\ASPNETDB.MDF 失败的。同名数据库 存在,或指定的文件不能 已打开,或者它位于 UNC 共享上。 文件激活失败。物理的 文件名 "C:\inetpub\wwwroot\Ordering\App_Data\ASPNETDB_log.ldf" 可能不正确。

【问题讨论】:

    标签: asp.net-mvc windows authentication


    【解决方案1】:

    您的网络配置中的这一行表明您使用的是 SQL 成员资格提供程序,而不是 Active Directory 成员资格提供程序。

    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
    

    或者你想使用这样的东西

    <add
           name="MyADMembershipProvider"
           type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, 
                 Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           connectionStringName="ADConnectionString"
           connectionUsername="testdomain\administrator" 
           connectionPassword="password"/>
    

    这是使用 Active Directory 的表单身份验证的参考链接 http://msdn.microsoft.com/en-us/library/ff650308.aspx

    【讨论】:

    • 好吧,我想这个想法是使用登录到 Windows 机器的用户的角色和 ID - 他们只登录一次。我的老板提到了活动目录
    • 即使这是 2.0 我也可以在我的 4.0 应用程序中使用它?
    【解决方案2】:

    尝试为网络服务添加显式读/写 ACL 到 App_Data(或只是 MDF 文件)。如果可行,那么您可能需要考虑为 Web 服务设置一个特定的服务帐户并在该 ID 下运行应用程序池。这将最大限度地减少数据库暴露给您的应用程序进行读/写。

    如果这不起作用,这个thread 可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      相关资源
      最近更新 更多