I have often came across a question where developer look to ways to get different page URL
Below example will show you have to get different url and its segments
Let us say my page URL is
http://localhost:51259/TEST.aspx?querystringOne=one
Below is code snippet to get different segments of URL
1= localhost
2= localhost:51259
3= 51259
4= /TEST.aspx
5= /
6= http://localhost:51259/TEST.aspx?querystringOne=one
7= /TEST.aspx?querystringOne=one
Below example will show you have to get different url and its segments
Let us say my page URL is
http://localhost:51259/TEST.aspx?querystringOne=one
Below is code snippet to get different segments of URL
Response.Write("<br/> 1= " + HttpContext.Current.Request.Url.Host);
Response.Write("<br/> 2= " + HttpContext.Current.Request.Url.Authority);
Response.Write("<br/> 3= " + HttpContext.Current.Request.Url.Port);
Response.Write("<br/> 4= " + HttpContext.Current.Request.Url.AbsolutePath);
Response.Write("<br/> 5= " + HttpContext.Current.Request.ApplicationPath);
Response.Write("<br/> 6= " + HttpContext.Current.Request.Url.AbsoluteUri);
Response.Write("<br/> 7= " + HttpContext.Current.Request.Url.PathAndQuery);
Response.Write("<br/> 2= " + HttpContext.Current.Request.Url.Authority);
Response.Write("<br/> 3= " + HttpContext.Current.Request.Url.Port);
Response.Write("<br/> 4= " + HttpContext.Current.Request.Url.AbsolutePath);
Response.Write("<br/> 5= " + HttpContext.Current.Request.ApplicationPath);
Response.Write("<br/> 6= " + HttpContext.Current.Request.Url.AbsoluteUri);
Response.Write("<br/> 7= " + HttpContext.Current.Request.Url.PathAndQuery);
Result from above code is as
1= localhost
2= localhost:51259
3= 51259
4= /TEST.aspx
5= /
6= http://localhost:51259/TEST.aspx?querystringOne=one
7= /TEST.aspx?querystringOne=one
Comments
Post a Comment