c# - Server.TransferRequest() and the http status code -


i had implement custom httpmodule handle 404 error in sharepoint.

it listens presendrequestcontent event, , looks 404 status code. if 1 found transferrequest.

void app_presendrequestcontent(object sender, eventargs e) {     httpresponse res = app.response;     httprequest req = app.request;      if (res.statuscode == 404 && !req.url.absolutepath.equals(pagenotfoundurl, stringcomparison.invariantcultureignorecase))     {         app.server.transferrequest(pagenotfoundurl);     } } 

this works fine, noticed in fiddler page showing 200 status code, though original request 404. not search engines.

is expected behaviour of transferrequest? can somehow maintain 404 status code? or, have been better off using old fashioned server.transfer?

update

i tried outside of sharepoint environment, , server.transferrequest request indeed give 200 status code, removing 404. server.transfer doesn't work don't think can given pipeline.

update 2

thanks answer below, have added following:

void app_postrequesthandlerexecute(object sender, eventargs e) {     httpresponse res = app.response;     httprequest req = app.request;      if (req.url.absolutepath.equals(pagenotfoundurl, stringcomparison.invariantcultureignorecase))     {         res.statuscode = 404;     } } 

well, transferrequest() triggers new request, implies new response. since resource pagenotfoundurl points does exist, client receives legitimate 200 ok status header.

you might want write http handler (or handle event in global.asax) in order force status header 404 not found when serving pagenotfoundurl.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -