in asp.net mvc 4 / mvc 5 how handle unauthorised url redirect error page. please 1 give suggestion
in check url xml file. xml file generate username or username int type.
public class logactionfilter:actionfilterattribute { public override void onactionexecuting(actionexecutingcontext filtercontext) { bool access= log("onactionexecuting", filtercontext.routedata); if (access == true) { //filtercontext.result=new redirectresult("~/user/not_assigned"); filtercontext.result = new redirecttorouteresult( new routevaluedictionary { { "controller", "error" }, { "action", "error" } }); } } private bool log(string methodname, routedata routedata) { var controllername = routedata.values["controller"]; var actionname = routedata.values["action"]; var message = string.format("{0} controller:{1} action:{2}", methodname, controllername, actionname); int id = convert.toint32(httpcontext.current.user.identity.name); xmldocument doc = new xmldocument(); string path=httpcontext.current.server.mappath("~/xmlfiles/"+id+".xml"); doc.load(path); xmlnodelist nodes=doc.selectnodes("/modules/module"); foreach (xmlnode node in nodes) { xmlnodelist cnodes = node.childnodes; foreach (xmlnode cnode in cnodes) { if (cnode.haschildnodes) { foreach (xmlnode chnode in cnode.childnodes) { if (chnode.attributes["controller"].innertext.tostring().equals(controllername.tostring(), stringcomparison.invariantcultureignorecase) && chnode.attributes["action"].innertext.tostring().equals(actionname.tostring(), stringcomparison.invariantcultureignorecase)) { string access = chnode.attributes["access"].innertext; if (access.equals("false", stringcomparison.invariantcultureignorecase)) { return true; } } } } else { if (cnode.attributes["controller"].innertext.tostring().equals(controllername.tostring(), stringcomparison.invariantcultureignorecase) && cnode.attributes["action"].innertext.tostring().equals(actionname.tostring(), stringcomparison.invariantcultureignorecase)) { string access = cnode.attributes["access"].innertext; if (access.equals("false", stringcomparison.invariantcultureignorecase)) { return true; } } } } } return false; } }
Comments
Post a Comment