Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring WCF Forms Authentication

In the implementation for my service I have:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

In my .config file I have:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

and:

  <system.web.extensions>
    <scripting>
      <webServices>
        <authenticationService enabled="true" requireSSL = "false"/>
      </webServices>
    </scripting>
  </system.web.extensions>

and:

<authentication mode="Forms" />

In the "Login" method for my service, I have:

FormsAuthentication.SetAuthCookie(request.UserName, false);

However, when I check:

HttpContext.Current.User.Identity.Name

It is an empty string. What am I missing?

like image 441
user89166 Avatar asked Nov 05 '22 21:11

user89166


2 Answers

Forms authentication is used when you want the user to fill out a login form.

For a service it would be better to use a different authentication mechanism.

like image 64
Shiraz Bhaiji Avatar answered Nov 15 '22 06:11

Shiraz Bhaiji


Try using ServiceContext.User.Identity instead.

like image 42
Tim S Avatar answered Nov 15 '22 05:11

Tim S