question

MJ-8053 avatar image
0 Votes"
MJ-8053 asked cooldadtx answered

Get directory

I have created an application that I want to use accross multiple websites on our server. I published the app to a location on the server. Then when I need to use that application on a website I open IIS and browse to the appropriate site and then make an app inside the directory where I want this to reside.

Uing code Is there a way to know which website that the app has been installed in?

For example when i make an app in a directory inside the Edison site I want it to say Edison, and when inside the King site i want it to say King.

Is this possible?

dotnet-aspnet-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered

If I follow what you're saying you're creating a sub app inside a site. Do be aware that web apps are designed to run in a sandbox so they really shouldn't be relying on anything outside what is in the root of the app. You are making the assumption here that your web app is a subapp of a website but to me that only makes sense if you're hosting multiple apps under the same site. It is a waste of resources to do otherwise.

As such inside the app everything is relative to the root and the parent site, if any, isn't relevant to the app. Even the file system path is hidden although accessible via MapPath. The best option you have is HttpRuntime. It exposes some of the web server data. One of these pieces of information is the app ID which is what IIS maps to each application. Given that you can query IIS to determine whether the app is a subapp or not.

Alternatively the HostingEnvironment class has some functionality to get site information. However I don't know if it returns the actual site data from a subapp or not. Furthermore many members in this class (and its referenced children) are for infrastructure use only so be careful it doesn't break later.

Personally I would make it a variable inside the configuration of the app since it would be static except when copying it.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.