in web.config
have configuration
-> system.webserver
-> modules
, have added module named basicauthhttpmodule
. has init
event assigns authenticaterequest
handler.
public void init(httpapplication context) { context.authenticaterequest += onapplicationauthenticaterequest; context.endrequest += onapplicationendrequest; } private static void onapplicationauthenticaterequest(object sender, eventargs e) { // find controller name here var request = httpcontext.current.request; }
in code above onapplicationauthenticaterequest
checks request.headers["authorization"]
, ensures user valid. not want happen specific controller though. tried adding allowanonymous
attribute , methods. no changes.
how find controller? requestcontext.routedata
doesn't contain anything. in requested url don't want parse string. seems hacky. also, server/controllerwithoutaccess/index?controllerwithaccess=1 contain name of controller allowing anonymous access reference different controller.
[edit]: ((system.web.httpapplication)sender).context.request
points request
variable in code. same. meanwhile, request.requestcontext.routedata
has null route
, null routehandler
, values
contains 0 items.
given seem have missing route
details, think you'll have recreate routing table based on current context:
private static void onapplicationauthenticaterequest(object sender, eventargs e) { var context = ((httpapplication)sender).context; var routedata = routetable.routes.getroutedata(new httpcontextwrapper(context)); var controllername = routedata.values["controller"]; ... }
keep in mind event going fire every image, css, script file well, expensive operation. may want interrogate request context more make intelligent decision whether need running more expensive code.
Comments
Post a Comment