ASP.NET Web API compatible with SimpleMembershipProvider?

Is it possible to use SimpleMembershipProvider with ApiController or is it just for classic web pages? When I try to use it, I get an error. The "Membership.Provider" property must be an instance of ExtendedMembershipProvider .

If it is compatible, how can I call a method. ValidateUser without creating a cookie like WebSecurity.Login?

UPDATE

I got it as part of the web APIs after the following changes:

  • Web.config : issue to the default member and role provider in the system.web tag that is inserted into the web API.

  • Change the InitializeSimpleMebershipAttribute template from the Mvc attribute to System.Web.Http.Filters . Attributes bound directly to the controller and Mvc do not work for ApiController .

However, the WebSecurity class mixes with forms authentication, and the .Login method attaches a cookie to the http header. WebMatrix.WebData provides a SimpleMembershipProvider but no .ValidateUser to use it in a neutral way of authentication.

Is SimpleMembership actually intended to be used with anything other than forms authentication? I can not find a clear answer to this on the Internet.

Thanks!

+4
source share
1 answer

I think I got an answer. See the comments section at the end of this page .

After initializing the SimpleMembershipProvider using the WebMatrix.WebData methods, the System.Web.Security.Membership class is available, as with the old MembershipProvider . Instead of using the WebSecurity class, Membership.ValidateUser is available for verification and the cookie is not attached to the http header.

+1
source

All Articles