Request.IsAuthenticated function in Asp.Net 5 -
is there equivalent request.isauthenticated in asp.net 5 hidden somewhere or expected loop through user's identities , determine ourselves?
if need know if user object authenticated, property should trick:
user.identity.isauthenticated if need prevent action being called unauthenticated user, following attribute class works great.
public class basicauthattribute : actionfilterattribute, iauthenticationfilter { public void onauthentication(authenticationcontext filtercontext) { } public void onauthenticationchallenge(authenticationchallengecontext filtercontext) { var user = filtercontext.httpcontext.user; if (user == null || !user.identity.isauthenticated) { filtercontext.result = new httpunauthorizedresult(); } } } i use in base controller class follows.
[basicauth] public abstract class baseauthorizedcontroller : controller
Comments
Post a Comment