Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the full url of the page I am on in C#

I need to be able to get at the full URL of the page I am on from a user control. Is it just a matter of concatenating a bunch of Request variables together? If so which ones? Or is there a more simpiler way?

like image 390
RedWolves Avatar asked Sep 02 '08 21:09

RedWolves


People also ask

How do I get a full URL?

Just right-click in Chrome's address bar select “Always show full URLs” to make Chrome show full URLs. Chrome will now always show the full URL of every web address you open. To disable this feature, right-click in the address bar again and uncheck it.

What is URL in asp net?

A request URL is simply the URL a user enters into their browser to find a page on your web site. You use routing to define URLs that are semantically meaningful to users and that can help with search-engine optimization (SEO). By default, the Web Forms template includes ASP.NET Friendly URLs.


2 Answers

Here is a list I normally refer to for this type of information:

Request.ApplicationPath :   /virtual_dir Request.CurrentExecutionFilePath :  /virtual_dir/webapp/page.aspx Request.FilePath :  /virtual_dir/webapp/page.aspx Request.Path :  /virtual_dir/webapp/page.aspx Request.PhysicalApplicationPath :   d:\Inetpub\wwwroot\virtual_dir\ Request.QueryString :   /virtual_dir/webapp/page.aspx?q=qvalue Request.Url.AbsolutePath :  /virtual_dir/webapp/page.aspx Request.Url.AbsoluteUri :   http://localhost:2000/virtual_dir/webapp/page.aspx?q=qvalue Request.Url.Host :  localhost Request.Url.Authority : localhost:80 Request.Url.LocalPath : /virtual_dir/webapp/page.aspx Request.Url.PathAndQuery :  /virtual_dir/webapp/page.aspx?q=qvalue Request.Url.Port :  80 Request.Url.Query : ?q=qvalue Request.Url.Scheme :    http Request.Url.Segments :  /     virtual_dir/     webapp/     page.aspx 

Hopefully you will find this useful!

like image 141
Mohsen Avatar answered Sep 18 '22 19:09

Mohsen


I usually use Request.Url.ToString() to get the full url (including querystring), no concatenation required.

like image 36
travis Avatar answered Sep 19 '22 19:09

travis