c# - ASP.NET MVC Redirect All Request if Condition Met -


i'm looking implement site wide redirect mvc5 app based on condition.

i've researched adding [authorize] base controller not adequate site runs on windows authentication need validate user present in separate, business owned hierarchy not connect ad.

i've researched filters , understand custom action filter may required here. trying implement correct way , should within project?

protected override void onactionexecuting(actionexecutingcontext filtercontext) {     if(staffid == 0)     {         filtercontext.result = redirecttoaction("error");     } } 

create custom authorize attribute, like:

public class staffonlyattribute : authorizeattribute {   protected override bool authorizecore(httpcontextbase httpcontext)   {       return staffid != 0;   }    protected override void handleunauthorizedrequest(authorizationcontext filtercontext)   {       base.handleunauthorizedrequest(filtercontext);       filtercontext.result = new redirecttorouteresult(new routevaluedictionary(new { controller = "yourcontroller", action = "error" }));   } } 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -