简体   繁体   中英

Specifying Application Name for WCF authentication

I am thinking to host same service for multiple clients on there respective virtual directories in IIS. so basically there will be one service on disk, that will be referenced by multiple IIS hosted virtual directories, this will give me some thing like this:

http://myservice/client1

http://myservice/client2

...etc

I will make the service contract generalized. this will give me one contract for all clients.

The underlying database would be different for all clients (schema is same), i will connect to the clients respective database by figuring out from the url used to access the service, if it was http://myservice/client1 i'll connect to dbClient1, if it was http://myservice/client2 i'll connect to dbClient2 ... etc

THE CHALLENGE:

the above will resolve most of the problems, except the authentication process (I am using ASP Membership, forms authentication). my service is on https basicHttp binding, so i don't have sessions.

How do I specify what application name to use for user authentication. (all clients have separate application names, stored in ONE ASP Membership Database) If i change at Global.asax under Application_AuthenticateRequest, it does work, as i can get the URL at that time, and specify the application name to be used while authentication, but this changes application name for other callers as well ... which is not good at all ....

So all i need is some way to tell my service that look for this username/password under this application in that database. (database would be same for all clients in authentication case). But i want the change of application name for that particular session/instance ... (not sure if these two are available in https basicHttp binding)

if i can resolve this matter i'll be all well ....

please help ... thanks

It appears that your using ASP.NET infrastructure for authentication. What kind of MemberShipProvider are you using? You need to write a custom provider that figures out the application name using the current request url. For example, here's the one that is based on SqlMembershipProvider :

public class MyMembershipProvider : SqlMembershipProvider
{

    public override string ApplicationName 
    { 
      get
      {
          var url = HttpContext.Current.Request.Url;
          // find out the application name from  url
      }
      set
      {
         base.ApplicationName = value;
      }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM