Server.Transfer in Global.asax

I have an error handler in the global.asax Application_Error method when an error occurs. I use the following code to transfer the user to the error page:

Server.Transfer("/Error/"); 

However, without specifying the actual name of the page, the code described above is broken into " Error executing child request on / Error / ".

Therefore, if I use Server.Transfer("/Error/Default.aspx") , it works fine without problems.

Also, using Response.Redirect("/Error/") works fine, however we want to continue to use Server.Transfer to keep the URL displayed in the address bar when the error page is displayed, so that users can simply refresh the page. to repeat access to the original URL.

I would appreciate it if anyone could comment on how to get the Server.Transfer method without specifying the actual aspx page name.

Many thanks.

+6
c # global-asax
source share
1 answer

Server.Transfer needs an actual virtual path to the resource, which will give the desired result. It does not go through IIS to find out what documents are by default for the website, so it does not know what you mean by "/ Error /" if that is not the actual file name.

Response.Redirect works because it sends the “moved” result to the browser with this relative URL (/ Error /), and when the browser makes a new request for / Error /, IIS processes it first and applies the default setting of the document.

+13
source share

All Articles