MyDaftQuestions
MyDaftQuestions

Reputation: 4701

How to capture parent URL path of masked URL

I have a website which has a controller that looks like this

public async Task<IActionResult> Index(string id)
{
    ViewBag.MyText = id; 
    return View()
}

Depending on the URL, if the id parameter is present, the value of the id shows on the webpage. My view displays ViewBag.MyText. EG, I visit mysite.com/controller/words then I see words on my web page. Likewise, if I visit mysite.com/controller/difwords then I see difwords on my web page.

I bought another URL which is set as a forwarder and masks the URL. Behind the scene, the new URL actually creates an iframe with my original site as the content of the iframe.

I don't seem to be able to grab the full URL that is shown in the browser from within my MVC app.

How do I get the path from the forwarding URL?

Upvotes: 0

Views: 40

Answers (2)

MikeJ82
MikeJ82

Reputation: 332

Depending on your individual network setup, the original host might also be availale in a header.

In that case, you might find the URL, you are looking e.g. in:

You can access these as follows.

Request.Headers["X-Forwarded-Host"];

Upvotes: 0

Ruikai Feng
Ruikai Feng

Reputation: 11939

We usually call

var path = HttpContext.Request.Path;

in controller to get the path

Upvotes: 0

Related Questions