Max Schmeling
Max Schmeling

Reputation: 12509

What is the best way to authenticate web users from WCF coming from ASP.Net web application?

I have an asp.net mvc 2 web application that connects to a WCF web service hosted in IIS. This is in an intranet environment using windows authentication. I need to authenticate the user connecting to the web application inside inside of my WCF service, but the WCF cannot see who connected to the web app.

This can't be a new problem, so how have some of you solved this issue?

Upvotes: 1

Views: 393

Answers (3)

AlexCuse
AlexCuse

Reputation: 18296

Is a shared session an option?

WCF offers an attribute (AspNetCompatibilityRequirements) that (presumably among other things) makes the session state ASP.net compatible. This in turn allows you to use out-of-process session state management that can be shared between applications.

You can enable this using

[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed]

And then in your configuration

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    ...
</system.serviceModel>

If you go the SQL Server route, I wrote this a while back. It is sharing between asp.net and an asmx service, but on the SQL Server side I imagine things are the same. Basically you need to make SQL Server recognize both parts of the system as the same application.

WCF also uses the same membership providers as ASP.net, so you might be able to get something going that way.

Upvotes: 0

ChrisNel52
ChrisNel52

Reputation: 15143

If you are using Windows Authentication, one option may be to use delegation to pass the caller's identity from the web app to the WCF service.

Upvotes: 0

Related Questions