asp.net custom HttpHandler and URL routing -
i want handle requests application "http://example.com/whateverpath" custom httphandler return things depending of value of "whateverpath".
so users accessing "http://example.com/path1" different response users accessing "http://example.com/path2", both request must handled in same httphandler. idea find "whateverpath" in database , depending of result, return response content.
i hear url routing , have custom http handler working, can combine both technique need?
i appreciate comment respect issue.
cheers frank abel
so have class implements ihttphandler
called: myhandler
, it's in namespace example
, need make following entries in site's web.config
in httphandlers section:
<httphandlers> <add verb="*" path="*" type="example.myhandler"/> </httphandlers>
since redirects urls web site/application handler have consider how serve static content (imgs, scripts, style sheets etc). 1 way store such static content in consistent url http://example.com/static/...
, can set handlers such:
<httphandlers> <add verb="*" path="*" type="example.myhandler"/> <add verb="get,head" path="static/*" type="system.web.staticfilehandler" /> </httphandlers>
for local dev webserver (embedded in visual studio) that's needed. iis, need tell iis how deal these urls (since server first analyses request decide send - including whether send asp.net or other extension).
- open: iis manager ->
- section: websites ->
- right click on website ->
- option: properties ->
- tab: home directoy ->
- button: [configuration...] ->
- tab: mappings ->
- section: "wildcard application maps (order of implementation):" ->
- button: [insert...] ->
- executable: "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll" (or whichever version of .net runtime handler uses) ->
- uncheck "verify file exists" ->
- button: [ok]
now both iis , asp.net know how deal urls.
the above approach means when requesting static files, asp.net serving files, not iis - leads few disadvantages (discussed here). can override behaviour (disable wildcard mapping static directory) switching directory application (in iis manager), removing wildcard mapping statement (added above) , switching application. voilĂ - static files handled iis without pestering asp.net.
Comments
Post a Comment