I'm using Asp.Net MVC. I want to know the url from which a request has been sent to my controller action.For example my controller action is(Customer/Index) and I want to get the url from which, my action is called.(I don't need the current URL).I want the source URL from which the request sent to me. Is there any solution?
Asked
Active
Viewed 1,630 times
0
-
Why would you need to know the full URL? – Tobias Tengler Jul 04 '19 at 08:43
-
you can use this Request.Url.AbsoluteUri: – Mangesh Auti Jul 04 '19 at 08:45
-
Possible duplicate of [Get URL of ASP.Net Page in code-behind](https://stackoverflow.com/questions/96029/get-url-of-asp-net-page-in-code-behind) – Mangesh Auti Jul 04 '19 at 08:46
-
@MangeshAuti Please explain why you think that duplicate target is related to this question, because it's not – Camilo Terevinto Jul 04 '19 at 08:51
-
@CamiloTerevinto OP want Request URL and this type of que already asked – Mangesh Auti Jul 04 '19 at 08:55
-
@MangeshAuti Really? You are reading the OP's mind then, because the question says "I want to get the url from which, my action is called" – Camilo Terevinto Jul 04 '19 at 08:55
-
@CamiloTerevinto then what does it mean ?? – Mangesh Auti Jul 04 '19 at 08:56
-
More Explanation: for example if someone send a request from www.SomeSite.com to my website, I want to know the www.SomeSite.com url. Or if the request come from my another controller-action, I want to know that url, Not the current url – Reza Makvandi Jul 06 '19 at 11:15
2 Answers
1
You could try using url referrer e.g.
Request.UrlReferrer
Request.QueryString["Referrer"].ToString()

mciesla
- 72
- 6
-
Request.UrlReferrer works if the request comes from outside of my website. But I want to know both coming requests from outside an inside my website. – Reza Makvandi Jul 06 '19 at 11:55
0
Have a look at this link: MDN reference
It states that "A Referer header is not sent by browsers if: The referring resource is a local "file" or "data" URI."
If you want to have that available if your page calls 'itself' i.e. another page/controller in you web application, you can try to add the header manually on a per request basis.

mnemonic
- 692
- 1
- 9
- 18