Request URL in ASP.Net

Suppose i am request a page http://localhost:57089/test/WebForm1.aspx?id=10 then what are the request property values in server side ? Many of the cases we need part of a request URL. Maybe Some times Port No or File Path or Exact file Name etc.

I just write the values in server side Request Property.

// Accessing http://localhost:57089/test/WebForm1.aspx?id=10
Response.Write( Request.RawUrl);
// /test/WebForm1.aspx?id=10
Response.Write( Request.Url.ToString());
// http://localhost:57089/test/WebForm1.aspx?id=10
Response.Write(Request.Url.AbsolutePath);
// /test/WebForm1.aspx
Response.Write(Request.Url.AbsoluteUri);
// http://localhost:57089/test/WebForm1.aspx?id=10
Response.Write("
" + Request.Url.Authority);
// localhost:57089
Response.Write(Request.Url.DnsSafeHost);
// localhost
Response.Write( Request.Url.Host);
// localhost
Response.Write(Request.Url.LocalPath);
// /test/WebForm1.aspx
Response.Write( Request.Url.OriginalString);
// http://localhost:57089/test/WebForm1.aspx?id=10
Response.Write( Request.Url.PathAndQuery);
// /test/WebForm1.aspx?id=10
Response.Write(Request.Url.Port.ToString());
// 57089
Response.Write(Request.Url.Query);
// ?id=10
Response.Write( Request.Url.Scheme);
// http
foreach (var Segment in Request.Url.Segments)
{
Response.Write("
" + Segment );
}
// [0] /
// [1] test/
// [2] WebForm1.aspx
Response.Write("
" + Request.QueryString);
// id=10
Response.Write( Request.PhysicalPath);
// C:\Users\user\documents\visual studio 2010\Projects\WebApplication3\WebApplication3\test\WebForm1.aspx
Response.Write( Request.PhysicalApplicationPath);
// C:\Users\user\documents\visual studio 2010\Projects\WebApplication3\WebApplication3\
Response.Write(Request.Path);
// /test/WebForm1.aspx
Response.Write(Request.ApplicationPath);
// /

 Response.Write("<br/>" + System.IO.Path.GetFileName(Request.Url.LocalPath));
//   WebForm1.aspx
Musthaan
Musthaan
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s