Home > ASP.NET > Get root path, root url and any url of your website asp.net

Get root path, root url and any url of your website asp.net

This technique will help you to get url and path of server that you want.
Let’s see this result.

When I place this script on this path below :

http://www.aspgod.com/test/mappath/Default.aspx

And the script is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Request.Url.AbsoluteUri  //  http://www.aspgod.com/test/mappath/Default.aspx
Request.Url.AbsolutePath  //  /test/mappath/Default.aspx
Request.ApplicationPath  //  because I'm not set the virsual directory indeep of the server
 
Server.MapPath("") // d:\xxx\zzz\aspgod.com\httpdocs\test\mapath
Server.MapPath("Default.aspx") // d:\xxx\zzz\aspgod.com\httpdocs\test\mapath\Default.aspx
 
if you want to get the root path and root url.
You must enter this script below:
 
Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,string.Empty) + Request.ApplicationPath
//  www.aspgod.com/
Server.MapPath(this.Request.ApplicationPath).Replace("/", "\\")
-> d:\xxx\zzz\aspgod.com\httpdocs

—–

If I use this script on localhost the the result is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Request.Url.AbsoluteUri  //  http://localhost:1904/aspgod/test/mappath/Default.aspx
Request.Url.AbsolutePath  //  /test/mappath/Default.aspx
Request.ApplicationPath  //  /aspgod
 
my project is in this path E:\--- Other Project ---\aspgod\program\aspgod
Server.MapPath("") // E:\--- Other Project ---\aspgod\program\aspgod\test\mapath
Server.MapPath("Default.aspx")
// E:\--- Other Project ---\aspgod\program\aspgod\test\mapath\Default.aspx
 
if you want to get the root path and root url.
You must enter this script below:
 
Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,string.Empty) + Request.ApplicationPath
//  http://localhost:1904/aspgod
Server.MapPath(this.Request.ApplicationPath).Replace("/", "\\")
// E:\--- Other Project ---\aspgod\program\aspgod

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

  1. KawdrowlFar
    October 2nd, 2009 at 13:13 | #1

    Hello! Base klooper for my english jer, buti plumb nice re say gJ$)Kd!!!.

  2. LDmytro
    December 6th, 2009 at 01:14 | #2

    Thank you!

  3. May 7th, 2011 at 18:09 | #3
  4. July 31st, 2011 at 20:03 | #4

    It’s funny goodluck danish lolita free photo 61028

  1. No trackbacks yet.