0

I'm already fairly certain the answer is no but can't seem to find a definitive answer. If I deploy an application that can be accessed by multiple host names, each host name will spin up its own separate instance of the application and static variables will not be shared between them, right?

EDIT: The hosting environment is IIS and there is only one website that has multiple bindings to different host names.

BVernon
  • 3,205
  • 5
  • 28
  • 64
  • @Igor Meaning, I assume, that each host name will get its own application domain even though it's on the same website. Thanks. – BVernon Oct 23 '18 at 16:38
  • 1
    @Igor I think it's perfectly fine to mark this a duplicate as the question has been answered and the referenced links provide additional useful information. But on principle I feel the need to point out that the question wasn't really about whether each AppDomain has its own space, but rather the question was about whether binding multiple host names to the same website results in multiple AppDomains or uses the same one. – BVernon Oct 24 '18 at 22:10
  • 2
    I misread your actual question. Could you [edit] it with the hosting platform and how is configured? That will determine if you have an appdomain per host or not. – Igor Oct 25 '18 at 01:16
  • @Igor Done. (blah blah blah to make up enough characters to post) – BVernon Oct 25 '18 at 05:01
  • Whether or not they're shared or not is mostly irrelevant. Trying to use static variables in an asp.net site is most often just the first step on a path to failure. Application pools, recycling, etc means that you've no guarantee that any two requests are going to be serviced by the same application instance. – Damien_The_Unbeliever Oct 25 '18 at 06:24
  • @Damien_The_Unbeliever That's absolutely fine as I'm looking up data based on the host name.The only scenario that could be bad is if clientOne.oursite.com and clientTwo.oursite.com shared this variable. It's just loaded once when the program starts and is read only. – BVernon Oct 25 '18 at 16:46

1 Answers1

1

IIS allows you to set the number of instances your website can actually run on. You will be able to access your variables if IIS is configured to run only a single instance and multiple domains are pointed to this single instance. Because of resource management, IIS will restart these instances when needed and oftenly. This is why if a request comes in and finds that IIS has already restarted the instance, it will have already lost the contents of the previous static variable values. However, if the same instance is found, the static variables will still mantain their values.

It is not recommended to use static variables for cross request message handling because most hosting providers do not use a single instance to run your website but may use a web farm to do so. This further leads us to why it is not good to use In-proc sessions when handling sessions. [Because the session values will be lost once the instance is restarted].

As of web farms, many instances are started to handle multiple incoming requests. So, one request may be handled by another instance different from the instance that handled the previous request. The new instance handling the request will definately not have the values of the variables of the other instance. Even if they are copies of the same website. This is because they are recognized as two different applications running on the server at the same time and the operating system does not permit direct sharing of the static variables accross the two different applications.

You can however make the best use of server side application settings in IIS or use cookies to route information accross multiple domains. These will enable you to for-example handle single login from a single website for all the other websites of your system. You can achieve this when the authentication website sets cookies for which can be accessed by the other websites. ASP.NET allows you to do such.

Thank you

Conrad
  • 118
  • 11
  • Thanks. I'm a bit unclear on one thing. You make it sound as though it 'is' possible for the site to be accessed via two different host names that would share the same AppDomain. I think this is probably not correct (as Igor pointed out in his comments), or perhaps I am misunderstanding you. – BVernon Oct 25 '18 at 16:52
  • Basically I'm just looking up customer info based on the host name used to access the site (i.e. if client1.oursite.com is accessed then it will contain data about client1, or if client2.oursite.com is accessed then it will contain data about client2). If the app pool resets or anything like that it will just reload the data... no big deal. It's only read; not written to so I don't care if the user hits different instances between requests. Only thing I can't have happen is the variable being updated each time a new client portal instance is started and that be shared between all the portals. – BVernon Oct 25 '18 at 16:58