开发者

Windows Authentication WCF and ASP.Net MVC2: getting users AD info to a wcf webservice

Hello there fellow StackOverflow and programming enthusiasts. I have a question, I am trying to move an MVC website that I created over to a test server so that users can start testing... I have run into a little issue that I overlooked when I developed 开发者_开发技巧the site. My website calls a service that I wrote that takes takes the service callers AD user name and uses it to do some back end work...

    private string CallerNameOnly = string.Empty;
    private string CallerFullDomain = string.Empty;

    public ACOService()
    {
        this.CallerFullDomain = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name.ToString();
        this.CallerNameOnly = this.CallerFullDomain.Substring(this.CallerFullDomain.IndexOf('\\') + 1);
    }

This worked just perfectly when I was developing on my local machine and my username was passed into the service just fine... However, I am having a hard time replicating the same functionality when I deploy to a server that I am using... For some reason, the current user ends up being my machine name... Now, I seemed to have isolated the issue to a setting in IIS 7 that when changed, changes the behavior of my website somewhat... If I go to the app pools advanced settings and I change the Process Model/Identity field, from LocalSystem, to any of the other Identity's It changes who the user is... My remote debugger kept bugging out on me so I couldn't figure out what the user name was, but you get the idea?

My question is, how do I get the username of the person using my website (which uses windows authentication) to call my web service with the username he used to access my site? I thought about getting the username and passing it directly into a constructor ie...

    public ACOService(string userID)
    {
        this.CallerNameOnly = userID;       
    }

but that presents problems, because I already have a constructor with a string in it. And I think I would have to place the constructor into my contract wouldn't I? How would that work in WCF anyway? Any help with this problem would be greatly appreciated.


You need to impersonate the client on the service.

http://msdn.microsoft.com/en-us/library/ms731090.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜