Web 服务不返回当前 Windows 用户名
这是我在 Web 服务中用于获取当前 Windows 用户的函数。
<WebMethod()> _
Function User() As String
Dim p() As String = Split(My.User.Name, "\")
Dim p1 As String = p(1)
Return p1
End Function
当我在本地主机上运行服务时,它确实返回当前的 Windows 用户名! 问题是当我从远程电脑运行服务时,在这种情况下我从这个功能中什么也得不到。该服务有什么问题,以及如何获取 Windows 用户的名称?
谢谢!
This is the function that I use in web service for getting current windows user.
<WebMethod()> _
Function User() As String
Dim p() As String = Split(My.User.Name, "\")
Dim p1 As String = p(1)
Return p1
End Function
When I run service on localhost it realy return current windows user name!
The problem is when i run service from remote PC, in that case I got nothing from this function. What is problem with this service, and how I can get name of Windows user?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您希望它返回哪个:调用者的身份?或者运行网络服务的服务帐户的身份?
在大多数情况下,windows 身份取决于服务器的配置方式;是否使用模拟?另外,您在呼叫服务时是否传递呼叫者身份?例如,
UseDefaultCredentials
或Credentials
。该服务是否配置为识别用户的声明?一般来说,我会尽量不使用模拟;它需要在服务器上提升,不支持所有环境,并且会对池的有效性产生很大影响 - 所以我不希望 windows 身份流动,但如果你通过某种形式的调用者身份我可能期望“主体”(
Thread.CurrentPrincipal
)代表调用者。我不记得来自 asmx,但是使用 WCF,如果需要,您可以编写自己的代码来根据自己的身份验证方案设置主体。
Which do you expect it to return: the identity of the caller? or the identity of the service account that is running the web-service?
In most cases the windows identity would depend on how the server is configured; is it using impersonation? Plus are you passing the callers identity over when calling the service? For example,
UseDefaultCredentials
orCredentials
. And is the service configured to recognise the users claims?Generally I try not to use impersonation; it requires elevation at the server, doesn't support all environments, and can have a big impact on the effectiveness of pooling - so I wouldn't expect the windows identity to flow, but if you are passing the callers identity in some form I might expect the "principal" (
Thread.CurrentPrincipal
) to represent the caller.I can't remember from asmx, but with WCF you can write your own code to setup the principal from your own authentication scheme if you want.
试试这个
Try this one
您可以通过以下代码行获取当前线程正在运行的身份:
You can get the identity the current thread is running under by the below line of code:
尝试:
Try: