Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top