用户DOMAINPC-NAME$登录失败

本文关键字:失败 登录 DOMAINPC-NAME 用户 | 更新日期: 2023-09-27 18:24:09

我现在正在调试一个intranet页面。我希望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处。

我在这里做错了什么?

用户DOMAINPC-NAME$登录失败

您的连接字符串是矛盾的:它想要使用用户名和密码,但同时想要使用集成安全性(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>