Tal
Tal

Reputation: 544

Getting the link for a virtual directory

I have written a server in C# for a JS client. The Solution consists restApi BL and DAL.

The BL creates links for images stored on a virtual directory, on the server. The JS and the server code, are stored in the same directory.

When I build the string of the link I use this line of code:

string keyImageName = Settings.Default.ServerUrl  + 
    Settings.Default.KeyImagesFolder + relatedFinding.KeyImagePath;`

where KeyImageFolder is a virtual directory.

It works fine, but my problem is that the website has multiple Amazon instances, one for each geographical zone , so every time I deploy, I need to change the ip in the settings.it's annoying.

Is there a way to get the virtual directory's url, specifically for each machine?

if the JS is installed on the same machine as the server, does it really need a full path?

Many thanks

Upvotes: 0

Views: 1791

Answers (1)

psaxton
psaxton

Reputation: 1843

First, you'll need to get the physical path for the file or directory that you want to generate a url for. This can be done within a Page object using Request.ApplicationPath.

Next, this path can be converted to a url path using the Server.MapPath function. This will take into account if there are more than one websites tied to the same path in IIS.

var physicalPath = Path.Combine(Request.ApplicationPath, Settings.Default.KeyImagesFolder, relatedFinding.KeyImagePath);
var resourceUrl = Server.MapPath(physicalPath);

Upvotes: 1

Related Questions