1

I'm currently redirecting a page using

Response.Redirect("URL");

this works great, however it changes the url too. For example:

http://localhost/index.aspx

Redirected to: test.aspx will change the url to:

http://localhost/test.aspx

Is it possbile to redirect the content without changing the URL?... so the Url will be:

http://localhost/test.aspx

BUT the content would of been redirected to

test.aspx

Thank you.

Joshua
  • 588
  • 1
  • 5
  • 19
  • 1
    There are ways of doing this (e.g. `Server.Transfer`) but they all have drawbacks depending on the specifics of your scenario. The reason for that being that this is not really what those tools are for and is quite an odd thing to try to do. Can I ask why you *want* to do this? It seems like a bad idea. – Ant P Nov 26 '14 at 09:51
  • It was just a check to see if the application was in maintenance mode. And if it was, to display that maintenance content.. But I wanted the users to be able to refresh the application and still be on the page that they was on in the first place. – Joshua Nov 26 '14 at 09:55
  • 2
    Perhaps you could consider the euchy iFrame alternative, keep the URL the same while serving different content... or perhaps an ajax update panel may be the better solution, or even a modal popup – Paul Zahra Nov 26 '14 at 10:00
  • Thanks, Okay then, I shall look a bit more in depth for this solution. – Joshua Nov 26 '14 at 10:01

2 Answers2

1

Try to use Server.Transfer(URL); to avoid changing the url.

More info here.

And also check the differences at this post and this one.

Make sure that this solution meets your needs.

Community
  • 1
  • 1
Giannis Grivas
  • 3,374
  • 1
  • 18
  • 38
1

Use Server.Transfer This will show the content of default.aspx page, but it will not change the url

Server.Transfer("Default.aspx");
mybirthname
  • 17,949
  • 3
  • 31
  • 55
  • Always love the downvote, plaese explain me why ? :) – mybirthname Nov 26 '14 at 09:53
  • Not my downvote, but blindly recommending `Server.Transfer` without further insight into the asker's scenario is not helping anyone. – Ant P Nov 26 '14 at 09:55
  • 1
    @AntP he asks for redirection to content of another page without changing the url. This is the scenario, Server.Transfer provides this logic ! – mybirthname Nov 26 '14 at 09:57
  • 1
    It's not that simple. `Server.Transfer` is applicable in very specific scenarios. Transferring the control of a single request to a separate .aspx file is not the only way of conditionally rendering different content and - in most cases - it's not the right one and has plenty of pitfalls. The use case/requirement needs to be interrogated further (i.e. displaying content from another page under the original page's URL is probably not the best solution to the problem in the first place). – Ant P Nov 26 '14 at 09:58