0

In an existing ASP.NET web application with the Identity Provider, using Forms Authentication, I'd like to authenticate a WCF AJAX Enabled Web Service using the user's already provided logon credentials for the site.

i.e. the WCF web service is only authenticated if the user has passed authentication for the forms website. No further authentication would be necessary for the WCF web service since it is hosted on the same web application.

The check if the user is authenticated would use the Identity framework code like

bool isUserAuthenticated= (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated

from How to check user is "logged in"?

The server-service code should be able to get the user's username from

System.Web.HttpContext.Current.User.Identity.GetUserId()

from ASP.NET MVC 5 - Identity. How to get current ApplicationUser

The context for a WCF web service is OperationContext, not HttpContext.

Joshua Ginn
  • 109
  • 2
  • 11
  • If I understand you correctly your question is does wcf web services still need to be authenticated after they have been authenticated by ASP.NET. – Jiayao Jan 04 '23 at 07:36
  • Yes, I believe they do. – Joshua Ginn Jan 15 '23 at 22:16
  • You can take a look at [this case](https://stackoverflow.com/questions/14093765/how-to-determine-user-is-authenticated-in-wcf-service). The solution may be helpful to you. – Jiayao Jan 31 '23 at 08:43

0 Answers0