1

If I have an assembly library (dll) that is referenced from within an ASP.NET MVC app, is it possible for the assembly to get to the server path without having to pass it in from the MVC app, or have access to HttpContext?

If I use a relative path, it will return the processes path. In the case of running locally in debug, it is:

C:\Program Files\IIS Express

However, the file lives in the bin output, with this DLL, and the rest of the site's binaries.

Is my only choice to pass the path in from the web app?

UPDATE

For now, I'm just using HttpContext.Current.Server.MapPath(), but I don't like having to use HttpContext, in the event that we consume this API from something other than a web app.

Jerad Rose
  • 15,235
  • 18
  • 82
  • 153

1 Answers1

0

To get the IIS server path that holds the web site you need HttpContext.Request.FilePath.

I pass the HttpContext into my library function, when I need to know where the web site is located.

However if you want to know the DLL's installed location, then I have seen it done using Assembly.Location

Old fart
  • 590
  • 1
  • 4
  • 12
  • There is `Assembly.GetAssembly().Location`, but this returns some temp path containing only this DLL. – Jerad Rose Jul 30 '14 at 17:04
  • http://stackoverflow.com/questions/18200650/where-are-the-assemblies-for-an-asp-net-web-site-when-running-iis-express – Old fart Jul 31 '14 at 11:38