Can the SimpleMembershipProvider
be used with a ApiController
or is it for classical web pages only? When trying to use it, I get the error "Membership.Provider" property must be an instance of ExtendedMembershipProvider
.
If it is compatible, how can I call the . ValidateUser
method without creating a cookie like WebSecurity.Login does?
UPDATE
I got it running within a Web API scaffolding after the following changes:
Web.config
: outcomment the default membership & role provider within the system.web
tag, as inserted by the Web API scaffolding.
Change the template InitializeSimpleMebershipAttribute
from a Mvc attribute to System.Web.Http.Filters
. The attributes hook directly into the controller and Mvc doesn't work for an ApiController
.
However, the WebSecurity
class is intermingled with forms authentication and the .Login
method attaches a cookie to the http-header. WebMatrix.WebData
exposes SimpleMembershipProvider
, but there is no .ValidateUser
to use it in a neutral way regarding authentication.
Is SimpleMembership
actually intended to be used with anything else than forms authentication? I cannot find a clear answer to that on the web.
Thanks!
I think I got the answer. See the remarks section at the end of this page .
After initializing a SimpleMembershipProvider
with the WebMatrix.WebData
methods, the System.Web.Security.Membership
class is available, just as with the old MembershipProvider
. Instead of using the WebSecurity
class for validation, Membership.ValidateUser
is available and no cookie attached to the http header.
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.