[英]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中与用户有关的服务器变量的更多信息是:
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.