c# - Authorize Attribute and popup dialog -


i need show popup dialog authorize clients, saw 1 solution authorize attribute launch modal. solution show private view modal dialog, if click close button of model dialog, still stay @ private view. it's not good, isn't? think too.

goal is: when click link of private view, check authorization. if client not authorized show popup dialog. if client inputted correct login/pass redirect private page.

how can this?

personalcontroller

public class personalcontroller : basecontroller {     [popupauthorize]     public actionresult index()     {         return view(baseviewobject);     }       [popupauthorize]     public actionresult personalprice()     {         return view(baseviewobject);     } } 

popupauthorizeattribute

[attributeusage(attributetargets.method | attributetargets.class, allowmultiple = true)] public class popupauthorizeattribute : authorizeattribute {     private void cachevalidatehandler(httpcontext context, object data, ref httpvalidationstatus validationstatus)     {         validationstatus = oncacheauthorization(new httpcontextwrapper(context));     }       protected override void handleunauthorizedrequest(authorizationcontext filtercontext)     {         base.handleunauthorizedrequest(filtercontext);     }       protected override httpvalidationstatus oncacheauthorization(httpcontextbase httpcontext)     {         return base.oncacheauthorization(httpcontext);     }     public override void onauthorization(authorizationcontext filtercontext)     {         debug.writeline("onauthorization");         bool isauthorized = false;         if (filtercontext == null) {             throw new argumentnullexception("filtercontext");         }         if (authorizecore(filtercontext.httpcontext)) {             httpcachepolicybase cache = filtercontext.httpcontext.response.cache;             cache.setproxymaxage(new timespan(0l));             cache.addvalidationcallback(cachevalidatehandler, null);             isauthorized = true;         }          filtercontext.controller.viewdata["openauthorizationpopup"] = isauthorized == false;     }  } 

_layout

  <!-- other html code -->   @if (user.identity.isauthenticated == false && ((bool)(viewdata["openauthorizationpopup"] ?? false))) {      @html.partial("_loginpartial", model.auth) } 


Comments