Issue Getting windows client display name in an .asmx service script in (VB) ASP.NET

StackOverflow https://stackoverflow.com/questions/18184383

  •  24-06-2022
  •  | 
  •  

Вопрос

I'm very new to ASP.NET and I've been struggling trying to get the username of the client sending requests to a web service script on the server side.

After searching online I found two properties that supposedly gives the server page access to the client username; User.Identity.Name and then I got another piece of code from an ex-senior colleague who left before figuring this problem out, his function used UserPrincipal.Current.DisplayName

and for both of these I'm getting a blank string.

I've searched for what my problem could be and I'm suspecting it's because I don't authenticate the user on the server side somehow. I just accessed those two properties/variables directly (UserPrincipal.Current.DisplayName and User.Identity.Name)

can anyone help shed some light on this issue please? I haven't a clue what I'm doing wrong/ not doing.

Это было полезно?

Решение

Your suspicions are correct; you have to explicitly authenticate the user via a built-in .NET mechanism such as Forms Authentication or Windows Authentication for User.Identity to be populated by the framework.

You didn't specify from where the requests are coming (web, windows app, windows service, etc), but this article provides nice overview of getting Forms Authentication set up with asmx.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top