2010-06-14 200 views
3

將我的應用程序轉移到Windows身份驗證存在實際問題。Windows身份驗證 - MVC 2 ASP.Net

sql錯誤消息是關於在aspnetdb.mdf文件中創建問題的。

我想知道在連接字符串是否存在故障或在web.config

的其他元素我有Windows身份驗證在IIS中設置。

的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的\訂貨\ App_Data文件\ ASPNETDB_log.ldf」。 「 操作系統錯誤5:」5創建文件遇到 操作系統錯誤5(未能 檢索此錯誤文本原因: 15105)試圖打開或創建 物理文件 「C:\的Inetpub \ wwwroot的\訂貨\ 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」 可能不正確。

回答

1

此行在您的Web配置狀態下使用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

+0

好吧,我想這個想法是使用登錄到Windows機器的用戶角色&id - 他們只做一個登錄。我的老闆已經提到了活動目錄 – bergin 2010-06-14 16:14:02

+0

即使這是2.0我可以使用它與我的4.0應用程序? – bergin 2010-06-15 08:38:25

+0

@ bergin.Yes你可以 – 2010-06-15 13:14:04

1

嘗試增加一個明確的讀/寫訪問控制列表到網絡服務的App_Data(或只是MDF文件)。如果可行,那麼您可能需要考慮爲Web服務設置特定的服務帳戶並在該ID下運行App Pool。這將最大限度地減少數據庫暴露給您的應用程序的讀/寫。

這個thread可能會有所幫助,如果這不起作用。