Dinuka Jayasuriya Dinuka Jayasuriya - 1 year ago 117
ASP.NET (C#) Question

ASP.NET: Getting the Current URL via a Web Method?

I'm trying to retrieve the URL of the current page via a Web Method. The code below works well on a normal C# Method such as the Page_Load but does not work inside a Web Method.

public static void UpdateProjectName(string name)
string project_id = HttpContext.Current.Request.Url.ToString();

I'm receiving an empty string ("") as the project_id. What am I doing wrong?

Answer Source

To get information of the client's previews request to current website you can use the UrlReferrer as follow:

//To get the Absolute path of the URI use this
string myPreviousAbsolutePath = Page.Request.UrlReferrer.AbsolutePath;

//To get the Path and Query of the URI use this
string myPreviousPathAndQuery = Page.Request.UrlReferrer.PathAndQuery;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download