在Windows身份验证中使用不同的域登录时如何处理错误?

时间:2013-06-12 22:59:42

标签: c# asp.net iis

我的asp.net应用程序使用aaa部署在域Windows Authentication中。用户尝试使用域bbb登录。它不会拒绝登录提示窗口。访问SQL服务器时抛出错误。

    Server Error in '/' Application.
    Login failed for user 'bbb\user'.
    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 
'bbb\user'.

    Source Error:      

    Line 7:          username = username.Substring(pos + 1)
    Line 8:          
    Line 9:          Clients = (From c In SGAEntities.Dim_Client
    Line 10:                    Where c.App_Users_Clients.Any(Function(userclient) userclient.App_Users.Username = username And userclient.App_Users.RecordStatus = 1 And userclient.Access_Level = 1)
    Line 11:                     Select c).ToList()


    Source File: error   Line: 9

    Stack Trace:

的Web.config

<authentication mode="Windows"/>
<authorization>
  <deny users = "?" />
</authorization>
<identity impersonate="true"/>

如何在尝试使用不同的域名登录时停止用户网站访问?

更新

正如朋友建议的那样,将模拟更改为false。得到不同的错误。

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中的起源位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:用户'NT AUTHORITY \ ANONYMOUS LOGON'登录失败。

来源错误:

第7行:username = username.Substring(pos + 1) 第8行: 第9行:客户=(来自c在SGAEntities.Dim_Client中 第10行:c.App_Users_Clients.Any(函数(userclient)userclient.App_Users.Username = username和userclient.App_Users.RecordStatus = 1和userclient.Access_Level = 1) 第11行:选择c).ToList()

数据库连接字符串是

    <add name="Entities" connectionString="metadata=res://*/Data.csdl|res://*/Data.ssdl|res://*
/Data.msl;provider=System.Data.SqlClient;provider connection string='data
source=server;initial catalog=database;Trusted_Connection=Yes;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />

2 个答案:

答案 0 :(得分:0)

在IIS中,确保未选择匿名访问,只需要选择集成的Windows身份验证。另外,我假设您在<system.web>部分提到了身份验证和授权标记。

答案 1 :(得分:0)

当您在IIS Express等下开发和运行时,Impersonate意味着它将您的Windows帐户用于SQL Server。当直接在IIS下运行,并且Impersonate关闭时,它将使用内置的匿名帐户。您应该确定是否真的希望如何设置SQL Server。

我过去所做的是创建SQL Server登录并在连接字符串中指定;或者,您可以配置SQL Server以授予IIS计算机权限。