0

I have hosted one site in IIS and ran the application. I have one exe which performs operation after reading the entries from MSMQ. So basically application add the task in MSMQ and exe reads that task and executes it.

I have one separate dll also in that dll I am preparing some href link of html dynamically. For doing this I need server dns and hosted sitename.

Ex: http://localhost/mysite/login.aspx from this url I need only http://localhost/mysite.

I am using this custom dll in one of task that exe executes.

Now the problem is I don't know how to get dns and site name because custom dll won't have HttpContext.Current object.

Mukund
  • 1,679
  • 1
  • 11
  • 20

3 Answers3

3

Use GetHostEntry together with GetHostName to get the DNS host name of the machine on which you make the call.

var hostname = Dns.GetHostEntry(Dns.GetHostName()).HostName;

To get the IIS virtual directory, follow the directions explained in the OS post How to get the IIS virtual dir & web application's physical paths with C# code:

ServerManager serverManager = new ServerManager();

// get the site (e.g. default)
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Default Web Site");

// get the application that you are interested in
Application myApp = site.Applications["/Dev1"];

// get the physical path of the virtual directory
Console.WriteLine(myApp.VirtualDirectories[0].PhysicalPath);
Community
  • 1
  • 1
Wicher Visser
  • 1,513
  • 12
  • 21
  • this will get me the hostname, but how I will get the virtual directory name of application which is hosted in IIS? – Mukund Apr 14 '16 at 10:28
0

You look for that asp.net function

GetHostEntry(string hostNameOrAddress)

There are also other commercial libraries that contains similar functions like aspNetDns that I prefer.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • this will get me the hostname, but how I will get the virtual directory name of application which is hosted in IIS? – Mukund Apr 14 '16 at 10:28
-2

I'm not sure I fully understood your problem, but what about to save URL you need in PATH on server and read it in your DLL?

  • How this is logical ? "I don't understand the problem but here is the answer..." and programming is about logic – Aristos Apr 14 '16 at 09:43
  • You should use comment section if you need more information on question, and should write the answer when you have one. – Afnan Apr 14 '16 at 10:40