Get the URL of the current page in C# - Asp.Net
Above code will return the absolute URL . "www.facebook.com", for example, or it will return localhost URL if you are in the local environment. It is important to note that Url.AbsoluteUri does return anything after the “#” symbol.
Also you can extract different values from URL using HttpContext.Current.Request
If you just need the part between "http://" and the first slash:
If you want only the scheme and authority of the request (protocol, host and port):
To get the port no. of the URL:
To get AbsolutePath :
To get Application path :
To get Path and Query :
To get complete URL of Current page:
What does this code mean?
It takes the url of the current web request, including the query string , and then extracts the part before the query string i.e. the part before the question mark (?).
- Difference between a Value Type and a Reference Type
- System level Exceptions Vs Application level Exceptions
- Difference between sub-procedure and function
- What does the term immutable mean
- What does the keyword static mean | C#
- this.close() Vs Application.Exit()
- Difference between a.Equals(b) and a == b
- Difference between Hashtable and Dictionary
- Difference between Error and Exception
- C# Dictionary Versus List Lookup Time
- Difference between the Class and Interface in C#
- Why does C# doesn't support Multiple inheritance