Last post Aug 06, 2016 04:49 AM by Yohann Lu
Aug 03, 2016 06:17 AM|varinderrai|LINK
I need to get URL of requesting web site in My WEB API 2. I need to do this because of security. I want to response to the request which are coming from the URLs that are registered on my server.
In Web API I have used
So far I have tried to get it from owin context and http context but no one gives URL. I am able to get IP address of the requesting web site.
Any idea how can I achieve this?
Aug 04, 2016 03:01 AM|Yohann Lu|LINK
At your WebAPI controller actions, you can use the following code to get requesting website urls.
public string Post([FromBody]string par)
//get call rul
//string url2= Request.RequestUri.ToString();
//string baseUrl = Url.Request.RequestUri.GetComponents(
//get request website url
string url3 = HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
// return (user.firstName.ToString() + " <> " + user.lastName);
return "333" + par;
Aug 04, 2016 10:10 AM|varinderrai|LINK
Yohann, I tried with this but UrlReferrer is received null.
Aug 06, 2016 04:49 AM|Yohann Lu|LINK
I have made a test on my side. It is working. I do not know why you can not get the URL of requesting website. I suggest you should make a test on your side and debug your code step by step.
Also, if you have any error in your code, you can post a new thread in relative forums and share more relevant code/message to help us reproduce the problem.