c# - enable mini profiler only to specific user and roles -
in asp.net mvc scott hanselman example shows how show mini profiler local environmnet
protected void application_beginrequest() { if (request.islocal) { miniprofiler.start(); } //or number of other checks, }
but, go step further , able see remotely, specific logged in users, or ips.
any idea how?
update: used following code:
protected void application_endrequest() { miniprofiler.stop(); //stop can, earlier mvcminiprofiler.miniprofiler.stop(discardresults: true); } protected void application_postauthorizerequest(object sender, eventargs e) { if (!isauthorizeduserforminiprofiler(this.context)) { miniprofiler.stop(discardresults: true); } } private bool isauthorizeduserforminiprofiler(httpcontext context) { if (context.user.identity.name.equals("levalencia")) return true; else return context.user.isinrole("admin"); }
you subscribe postauthorizerequest
event , discard results if current user not in given role or request coming specific ip or whatever check want:
protected void application_beginrequest() { miniprofiler.start(); } protected void application_postauthorizerequest(object sender, eventargs e) { if (!dothecheckhere(this.context)) { miniprofiler.stop(discardresults: true); } } private bool dothecheckhere(httpcontext context) { // checks here return context.user.isinrole("admin"); }
Comments
Post a Comment