简体   繁体   English

从Web应用程序检索原始用户身份

[英]Retrieving original user identity from web application

Summary of the question : In ASP.net, if you use credentials to invoke a web service, how can you retrieve the original user logged in to the web application calling the web service? 问题摘要 :在ASP.net中,如果您使用凭据来调用Web服务,那么如何检索登录到调用Web服务的Web应用程序的原始用户?

Explanation: 说明:

We have a web application, invoking a web service. 我们有一个Web应用程序,正在调用Web服务。 Both are ASP.NET, currently 2.0. 两者都是ASP.NET,当前为2.0。

The user logs in to the web application (Windows authentication), but to call the web service we use specific credentials: 用户登录到Web应用程序(Windows身份验证),但是要调用Web服务,我们使用特定的凭据:

   proxy.PreAuthenticate = true;
   proxy.Credentials = new System.Net.NetworkCredential(UserName, Password);

From the invoked web service, if we access the identity attribute of the webservice class ( WebService.User.Identity ) it gets the original user logged in , not these credentials. 从调用的Web服务中,如果我们访问Web服务类( WebService.User.Identity )的identity属性,它将获得原始用户登录 ,而不是这些凭据。

However, when switching to Federation Authentication and .NET 4 in the web service, now WebService.User.Identity retrieves the special credentials. 但是,当在Web服务中切换到联合身份验证和.NET 4时,现在WebService.User.Identity检索特殊凭据。

Summing up, invoking the same web method with the same credentials, WebService.User.Identity returns: 总结一下,使用相同的凭据调用相同的Web方法,WebService.User.Identity返回:

  • .NET 2 + Windows authentication: original username of the logged in user .NET 2 + Windows身份验证:已登录用户的原始用户名

  • .NET 4 + Federation authentication: credentials used in the method call .NET 4 +联合身份验证:方法调用中使用的凭据

How can I change it to get the original user logged in in .NET 4 with federation authentication? 如何更改它以使原始用户通过联合身份验证登录.NET 4?

EDIT: Some more information, in .NET 2 the server variables related to the user are: 编辑: .NET 2中与用户有关的服务器变量的更多信息是:

  • AUTH_USER: user logged in AUTH_USER:用户已登录
  • LOGON_USER: special user credentials LOGON_USER:特殊用户凭据
  • REMOTE_USER: user logged in REMOTE_USER:用户已登录

And as I said, in .NET 4 the 3 server variables are the special user credentials. 就像我说的那样,在.NET 4中,这3个服务器变量是特殊的用户凭据。

Hi Can you give a try to below code to get the original logged in user: 嗨,您可以尝试以下代码获取原始登录用户:

        string serverVariable = Request.ServerVariables["AUTH_USER"].ToString();
        string[] authUser = serverVariable.Split('\\');
        string strUserName = authuser[0];
        string strDomain = authUser[1];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Web App中使用User.Identity.Name检索AD用户 - Retrieving AD user using User.Identity.Name in Web App 从Web应用程序(EF,ASP.NET Identity,Azure)中删除注册并从DB注册用户 - Remove registration from web application (EF, ASP.NET Identity, Azure) and register a user from DB 将用户身份从MVC传递到Web Api - Passing user identity from MVC to Web Api 如何在Web n层应用程序中传递用户身份以便从用户界面层到数据访问层进行审计? - How to pass user identity in a web n-layer application for auditing purposes from the User Interface Layer to the Data Access Layer? 使用 Microsoft 标识为 ASP.NET 核心 web 应用程序检索不记名令牌 - Retrieving a Bearer token using Microsoft Identity for an ASP.NET core web application 从IEnumerator检索原始类型 - Retrieving the original type from an IEnumerator 在.NET Core Web应用程序中存储Identity Server的访问令牌 - Storing access token from Identity Server in NET Core web application 从桌面应用程序到Web应用程序的身份验证用户 - Authentication user to web application from desktop application 使用身份从 Web Api 2 中的数据库中删除用户 - Delete user from database in Web Api 2 using Identity 使用EF和Linq从数据库检索数据时访问Identity用户的其他属性 - Accessing additional properties of an Identity user when retrieving data from the database using EF and Linq
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM