简体   繁体   English

将ASP.NET Web API托管为Windows服务时如何获取用户名

[英]How to get user name when ASP.NET web api hosted as windows service

We are running a asp.net mvc application (client - this app is accessed through browser by user) which makes use of HttpClient class to make calls to asp.net web api application (server- I want to access the user information user. Person who invoked the client application). 我们正在运行一个asp.net mvc应用程序(客户端-该应用程序可通过用户通过浏览器访问),该应用程序利用HttpClient类调用asp.net web api应用程序(服务器,我想访问用户信息用户。谁调用了客户端应用程序)。 This is a intranet application. 这是一个Intranet应用程序。 We are hosting asp.net web api as windows service. 我们托管asp.net Web API作为Windows服务。 How can I get the user name in this scenario? 在这种情况下如何获取用户名?

ApiController class has a property public IPrincipal User { get; } ApiController类具有一个属性public IPrincipal User { get; } public IPrincipal User { get; } . public IPrincipal User { get; } I looked this property and this is what i got: 我看了这个属性,这就是我得到的:

User.Identity.AuthenticationType = ""; User.Identity.AuthenticationType =“”; User.Identity.IsAuthenticated = false; User.Identity.IsAuthenticated = false; User.Identity.Name = "" User.Identity.Name =“”

Is it possible to get some valid value from User.Identity with this kind of setup? 通过这种设置是否可以从User.Identity获得一些有效值?

It depends on which user you want, the user running the website service / app pool (EG networkservice), or an authenticated user that logged into your website. 它取决于您想要的用户,运行网站服务/应用程序池(EG网络服务)的用户或登录到您网站的经过身份验证的用户。 Assuming you have the user logging in and auth set up in IIS, this might do to pass along the creds, which you could then extract in your API. 假设您已经在IIS中登录了用户并进行了身份验证,那么这样做可以传递凭据,然后您可以将其提取到API中。

using (HttpClient httpClient = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))

Hard to say for sure without a whole bunch of details. 没有大量细节就很难确定。

暂无
暂无

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

相关问题 如何使用ASP.NET WEB API 2获取Window登录的用户名和密码 - How to get Window's logged in User Name and Password using ASP.NET WEB API 2 ASP.NET web应用——如何获得Windows用户? - ASP.NET web application -- how to get Windows user? 如何在asp.net中使用Windows身份验证获取用户名? - How to get user name using Windows authentication in asp.net? Azure上托管的Asp.net后端和Web API Web服务如何将推送通知发送到移动应用程序? - How do Asp.net backend and Web API web service hosted on Azure send push notification to mobile app? Windows服务中托管的WCF可以模拟来自asp.net Web应用程序的域Windows调用者吗? - Can a WCF hosted in windows service impersonate a domain windows caller from asp.net web application? 当用户运行托管 IIS 链接时,如何在 asp.net 中获取客户端 IP 地址 - How to get the client IP address in asp.net when user runs hosted IIS link 通过调用外部ASP.NET Web Api服务对ASP.NET MVC Web应用程序中的用户进行身份验证 - Authenticate a user in an ASP.NET MVC web application by calling an external ASP.NET Web Api service 通过共享Windows托管服务器上托管的ASP.NET Web API应用程序,Google API调用失败 - Google API call fails from an ASP.NET Web API application hosted on shared Windows hosting server 与Windows服务上托管的WCF服务的ASP.net服务器连接 - ASP.net server connection with WCF service hosted on windows service 自签名ASP.NET Web API 2 REST服务的令牌身份验证和授权 - Token authentication and authorisation for a self-hosted ASP.NET Web API 2 REST service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM