How do I restrict access to certain pages in ASP.NET MVC? -
i wish lock out access html page (eg. /manual/manual_a/index.html) if condition not met (eg. httpcontext.current.request.form["key"].tostring().equals("a") ), wish redirect specific view (eg. /errorpage/) else continue (eg. /index). in register route add:
routes.maproute( "errorpage", "errorpage/", new { controller = "home", action = "errorpage" } ); routes.maproute( "path", "{*_request}", new { controller = "home", action = "index" } );
for read request. in controller home
[customauthorize] public actionresult index() { } protected override void onactionexecuting(actionexecutingcontext filtercontext) { if(!condition) filtercontext.result = redirecttoaction("pageerror"); }
onactionexecuting executes on every request, however, redirecttoaction not happen. hints i'm doing wrong?
you need set filtercontext.result
shown below , redirect error page.
filtercontext.result = new emptyresult(); redirecttoaction("pageerror");
that should fix problem.
Comments
Post a Comment