Role Provider / Membership? How to in asp.net web api? -
i building asp.net mvc web api application , not sure how membership stuff.
in current project have this
my own users table
, role table
not using asp.net membership brings baggage , not fit how want design database(sure can seems work)
a user
can have many roles , role
can have many users.
i using ef calls database.
in past projects made own authorize attribute
did own call database , checked see if user in correct role allowed on controller/action method.
by not doing membership providers lost out on of built in functions such user.isinrole
. still able use user.identity.name
think because of cookie set.
what best practice way in asp.net mvc 4/web api?
while googling found "simplemembership" have not read yet.
on side note can use user.identity.name
webapi if authenticated user?
here article describes how create custom authorize attribute web api's using simplemembership. not have use simplemembership, although flexible , easy use. take same concepts in article , use membership service instead, long service can verify specific user in role, log user in , out, , verify authenticated.
if service not verify authenticated can use user.identity.isauthenticated , can use user.identity.name logged in usersname; assuming service correctly sets thread.currentprincipal when user logs in. recommended practice set httpcontext.current.user. of course not have worry of if use simplemembership.
this custom authorize attribute support both forms authentication , basic authentication in case expose api's public. different authorize attribute used on controller in returns http status code of forbidden if not authorized , unauthorized if not authenticated; instead of redirecting log-on page.
Comments
Post a Comment