0

Is it possible to configure the route within a asp.net mvc project when redirecting to an external url?

for example

public ActionResult MyUrl()
{
    return Redirect("http://www.myurl.com/");
}

I dont want the the url of http://www.myurl.com/ to be displayed in the address bar but

MyProject/MyUrl

I tried this

routes.MapRoute(null, "MyUrl", new { controller = "Home", action = "MyUrl" });
Mathieu Longtin
  • 15,922
  • 6
  • 30
  • 40
Arianule
  • 8,811
  • 45
  • 116
  • 174
  • You need to make "transfer", look here http://stackoverflow.com/questions/799511/how-to-simulate-server-transfer-in-asp-net-mvc – Backs Aug 11 '15 at 14:25
  • I think Server.TransferRequest has replaced transfer. https://msdn.microsoft.com/en-us/library/aa344901(v=vs.110).aspx – Andy Nichols Aug 11 '15 at 14:27

1 Answers1

1

For external URL you could not use Server.TransferRequest. This method just works for same site. Use iframe to your view instead:

public ActionResult MyUrl()
{
    return View();
}

In your view use iframe with external URL:

<body>
    <iframe src="http://www.myurl.com/"></iframe>
</body>

By using this method user see MyProject/MyUrl in the address bar. But keep in mind user could easily discover actual URL by viewing source of HTML file.

Sam FarajpourGhamari
  • 14,601
  • 4
  • 52
  • 56