2013-07-22 40 views
0

我正在調試內部網頁。我希望該頁面可供DOMAIN中的所有人訪問,並且爲此我啓用了Windows身份驗證,但給了我的連接字符串數據庫上SQL帳戶的用戶名和密碼,並具有讀取權限。

這是怎麼了,我從我的表打印:

<div style="min-height: 150px; font-size: 1.25em"> 
    <div style="margin-bottom: .5em"> 
     <table><thead><tr><th>Name</th><th>Branch</th><th>Phone No.</th><th>Username</th><th>Email</th></tr></thead> 
      <tbody> 
      @foreach (var prod in Model) 
       { 
        <tr> 
         <td>@prod.FullName</td> 
         <td>@prod.Branch</td> 
         <td>@prod.PhoneNo</td> 
         <td>@prod.DomainAC</td> 
         <td>@prod.Email</td> 
         @if (User.IsInRole(@"Admins") || User.Identity.Name == prod.DomainAC) { 
           <td><a href="/home/edit/@prod.Id" style="color: blue;">edit</a></td> 
         }else{ 
         <td>User => @User.ToString()</td> 
         } 
        </tr> 
       } 
       </tbody> 
      </table> 
     </div> 
    </div> 

所以,你可以看到,我希望用戶能夠編輯他們的詳細信息,如果域帳戶他們登錄的==帳戶在數據庫中。

我的web.config文件看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXX" requirePermission="false" /> 
    </configSections> 
    <appSettings> 
    <add key="webpages:Version" value="2.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="PreserveLoginUrl" value="true" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation targetFramework="4.5" debug="true"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
    <authentication mode="Windows" /> 
    <authorization> 
     <deny users="?" /> 
    </authorization> 
    <pages> 
     <namespaces> 
     <add namespace="System.Web.Helpers" /> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Optimization" /> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Web.WebPages" /> 
     </namespaces> 
    </pages> 
    </system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
    <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate" /> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="xxxxxxxxxxxxx" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="xxxxxxxxxxxxxxxx" /> 
     <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="xxxxxxxxxxxxxxxxxxxx" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="xxxxxxxxxxxx" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    </entityFramework> 
    <connectionStrings> 
    <add name="Entities" connectionString="metadata=res://*/Models.EmployeesDBModel.csdl|res://*/Models.EmployeesDBModel.ssdl|res://*/Models.EmployeesDBModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=APP1;Initial Catalog=&quot;Test Database&quot;;Integrated Security=True;user id=AnonUser;password=AnonUser;Application Name=EntityFramework'" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <system.web> 

     <customErrors mode="Off"/> 
    </system.web> 
</configuration> 

目前這導致:

Login failed for user DOMAIN\PC-NAME$ 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'DOMAIN\PC-NAME$'. 

它發生在上面的代碼提取物在foreach。

我在這裏做了什麼不對?

回答

3

您的連接字符串是矛盾的:它想要使用用戶名和密碼,但同時希望使用集成安全性(Windows帳戶驗證)。由於您指定了Integrated Security=True,因此連接到數據庫的用戶將是運行該進程的用戶,在這種情況下,您的網站的應用程序池在IIS中的身份。刪除Integrated Security=True,它應該使用提供的用戶名和密碼。

<connectionStrings> 
    <add name="Entities" 
     connectionString="metadata=res://*/Models.EmployeesDBModel.csdl|res://*/Models.EmployeesDBModel.ssdl|res://*/Models.EmployeesDBModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=APP1;Initial Catalog=&quot;Test Database&quot;;user id=AnonUser;password=AnonUser;Application Name=EntityFramework'" 
     providerName="System.Data.EntityClient" /> 
</connectionStrings> 
+0

啊,上帝,這是一個尷尬的錯誤!謝謝! :) –

相關問題