BalaKrishnan웃
BalaKrishnan웃

Reputation: 4557

Request.ApplicationPath is in not working

My app is structured like this:

 MyProject
    -Tracking
      - TrackingPage.aspx
    -master
      -mymaster

in the mymaster page, I have link like this:

 string sApplicationPath = Request.ApplicationPath;

pStr = pStr + "<li id='Home'><a class='top' href='";
        pStr = pStr + sApplicationPath;
        pStr = pStr + "/Tracking/TrackingPage.aspx'>Home</a></li>";

When run the app in it works, but when I put that in IIS, it gives me:

 http://117.**.**.134/mysit/Tracking/TrackingPage.aspx.

when I click the link it navigates me to wrong palce:

http://117.**.**.134/mysit/master/Tracking/TrackingPage.aspx.

How to can I fix this issue?

Upvotes: 1

Views: 2837

Answers (1)

Bazzz
Bazzz

Reputation: 26932

I think you want to get the hostname of the current URL? If so have a look at:

Request.Url

You can also have a look at the properties of the Uri class, to see what you can extract from the URL, or you can create a new Uri with the old one and a relative path string or Uri.

Uri class

Eventually I think what you want to do is:

Uri url = new Uri(Request.Url, "/Tracking/TrackingPage.aspx");
pStr = pStr + "<li id='Home'><a class='top' href='";
pStr = pStr + url.ToString();
pStr = pStr + "'>Home</a></li>";

Upvotes: 2

Related Questions