Arianule
Arianule

Reputation: 9043

Access to url from within an mvc project

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" });

Upvotes: 0

Views: 120

Answers (1)

Sam FarajpourGhamari
Sam FarajpourGhamari

Reputation: 14741

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.

Upvotes: 1

Related Questions