Server.Transfer in Global.asax
Asked Answered
A

1

10

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

Server.Transfer("/Error/");

However without specifying the actual page name the code above breaks with "Error executing child request for /Error/" exception.

So if I use Server.Transfer("/Error/Default.aspx") it works fine with no problems.

Also using Response.Redirect("/Error/") works fine too, however we want to keep using Server.Transfer to retain URL displayed in the address bar when the error page is displayed so users can simply refresh the page to retry accessing the original offending URL.

Would be grateful if anyone can comment on how to get the Server.Transfer method working without specifying the actual aspx page name.

Many thanks.

Apron answered 29/12, 2010 at 11:14 Comment(2)
Does the Server.Transfer without a specific page work on a regular page? If the Server.Transfer hides the page name, why is including it in the transfer a problem?Excerpt
I know what you mean, really including the page name in the code won't affect how end users see it, I was just trying to seek a bit of perfection as all of our paths are declared as constants and thought that Server.Transfer could follow the convention here. I guess I will have just to make an exception for this instance and include the full path. Thanks.Apron
A
15

Server.Transfer needs the actual, virtual path to a resource that will give the output needed. It does not go through IIS to find out what the website's default document(s) are, so it has no clue what you mean by "/Error/" unless that is an actual file name.

Response.Redirect works because that is sending a 'moved' result to the browser with that relative URL (/Error/) and when the browser makes the new request for /Error/, IIS handles it first, and applies the default document settings.

Aciculum answered 29/12, 2010 at 11:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.