In this article, I will give some examples to how to get current page url using asp.net and c#. "Page" class will provide the properties to get all details about the current page like Page Name, Page Path (Virtual and Physical), Query Strings etc.,

If your website url is like this
http://www.venkateswarlu.net/dotnet/articles.aspx?query=test

Below are the list prorperies you can rad from Page Class.




















Page.AppRelativeTemplateSourceDirectory~/
Page.AppRelativeVirtualPath~/dotnet/articles.aspx
Page.Request.AppRelativeCurrentExecutionFilePath~/dotnet/articles.aspx
Page.Request.ApplicationPath/dotnet
Page.Request.CurrentExecutionFilePath/dotnet/articles.aspx
Page.Request.CurrentExecutionFilePathExtension.aspx
Page.Request.FilePath/dotnet/articles.aspx
Page.Request.Path/dotnet/articles.aspx
Page.Request.PhysicalApplicationPathC:\repo\project1\
Page.Request.PhysicalPathC:\repo\project1\dotnet\articles.aspx
Page.Request.RawUrl/dotnet/articles.aspx?query=test
Page.Request.Url.AbsolutePath/dotnet/articles.aspx
Page.Request.Url.AbsoluteUrihttp://www.venkateswarlu.net/dotnet/articles.aspx?query=test
Page.Request.Url.Hostwww.venkateswarlu.net
Page.Request.Url.IdnHostwww.venkateswarlu.net
Page.Request.Url.LocalPath/dotnet/articles.aspx
Page.Request.Url.OriginalStringhttp://www.venkateswarlu.net:8080/dotnet/articles.aspx?query=test
Page.Request.Url.PathAndQuery/dotnet/articles.aspx?query=test
Page.Request.Url.Query?query=test
Page.Request.UserHostAddress111.222.3.444

Query

  1. Dictionary<string, string> dic = new Dictionary<string, string>();
  2. dic.Add("Page.AppRelativeTemplateSourceDirectory", Page.AppRelativeTemplateSourceDirectory);
  3. dic.Add("Page.AppRelativeVirtualPath", Page.AppRelativeVirtualPath);
  4. dic.Add("Page.Request.AppRelativeCurrentExecutionFilePath", Page.Request.AppRelativeCurrentExecutionFilePath);
  5. dic.Add("Page.Request.ApplicationPath", Page.Request.ApplicationPath);
  6. dic.Add("Page.Request.CurrentExecutionFilePath", Page.Request.CurrentExecutionFilePath);
  7. dic.Add("Page.Request.CurrentExecutionFilePathExtension", Page.Request.CurrentExecutionFilePathExtension);
  8. dic.Add("Page.Request.FilePath", Page.Request.FilePath);
  9. dic.Add("Page.Request.Path", Page.Request.Path);
  10. dic.Add("Page.Request.PhysicalApplicationPath", Page.Request.PhysicalApplicationPath);
  11. dic.Add("Page.Request.PhysicalPath", Page.Request.PhysicalPath);
  12. dic.Add("Page.Request.RawUrl", Page.Request.RawUrl);
  13. dic.Add("Page.Request.Url.AbsolutePath", Page.Request.Url.AbsolutePath);
  14. dic.Add("Page.Request.Url.AbsoluteUri", Page.Request.Url.AbsoluteUri);
  15. dic.Add("Page.Request.Url.Host", Page.Request.Url.Host);
  16. dic.Add("Page.Request.Url.IdnHost", Page.Request.Url.IdnHost);
  17. dic.Add("Page.Request.Url.LocalPath", Page.Request.Url.LocalPath);
  18. dic.Add("Page.Request.Url.OriginalString", Page.Request.Url.OriginalString);
  19. dic.Add("Page.Request.Url.PathAndQuery", Page.Request.Url.PathAndQuery);
  20. dic.Add("Page.Request.Url.Query", Page.Request.Url.Query);
  21. dic.Add("Page.Request.UserHostAddress", Page.Request.UserHostAddress);
  22. dic.Add("Page.Request.UserHostName", Page.Request.UserHostName);
  23. GridView1.DataSource = dic;
  24. GridView1.DataBind();