开发者

C# Private variables in classes over Web Service calls not working?

I am trying to figure out what user is calling my web service. To do this, I would like to pass in the Environment.UserName. However, if its just a string, then anyone writing their own client can just put in "asdf" and bypass what I am trying to do. So declared a public class in my Web Service:

public class UserInfo
{
    private string userName;

    public UserInfo()
    {
        userName = Environment.UserDomainName + "/" + Environment.UserName + " on " + Environment.MachineName;
    }
    public string getUserName()
    {
        return userName;
    }
}

Now when I call:

ClientTest.ServiceReference.UserInfo user = new ClientTest.ServiceR开发者_如何学Ceference.UserInfo();

in my client, I thought it would get my information ("Domain/Me on MyComputer"). It does not. The web service will gets its information ("NT AUTHORITY/NETWORK SERVICE on ServerComputer")

Is there anyway to revise my code to get this to work? Is this even possible with my solution? Is there a better way?


I don't think Environment is what you want to be using. It looks like all you are doing is getting the domain, username and machine that the service is running under, not of the user trying to access the service.

I believe what you want is the WebService.Context object. This gives you access to information regarding the HTTP client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜