Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic Properties/Collections Not Executing Properly Inside ASP.NET Application
    primarykey
    data
    text
    <p>We are currently working on a multi-tenant application that is running into some random strange behavior in relation to how it deals with the multi-tenancy aspect. </p> <p>Background: We have an ASP.NET application that is to be used by multiple groups of end users. The URL that they use to access the application determines which company they are associated with and eventually their database connection string. We store a static list of CompanyHost mappings that map the specific Company ID to host name. If we don't find a match in the static list we re-pull the list from the database. </p> <p>When the application first starts up it correctly pulls up the connection finding the correct Company ID for a host. However, after an unknown period of time the application will start returning an empty ID for all host headers, even if they exist inside of the database causing the application to be unable to determine the connection string. Going onto the server and recycling the application pool resolves the issue. I have attempted to set the Application Pool recycle time to something low (2 hours) to try and avoid it however it is either not low enough or is not the problem.</p> <p>Here is the snippet that gets the company ID by host. This is returning an Empty Guid even for a valid host name.</p> <pre><code>private static List&lt;CompanyHost&gt; lCompanyHosts = new List&lt;CompanyHost&gt;(); public static string Host { get { return HttpContext.Current.Request.Url.DnsSafeHost; } } public static Guid CompanyIDByHost { get { Guid gCompany_ID = Guid.Empty; lock (lCompanyHosts) { if (lCompanyHosts.Count == 0) lCompanyHosts = new CompanyHostDataLogic().RetrieveAll(); gCompany_ID = lCompanyHosts.Where(ch =&gt; ch.hostname.ToLower() == Host.ToLower()).Select(ch =&gt; ch.company_id).FirstOrDefault(); if (gCompany_ID == Guid.Empty) { lCompanyHosts = new CompanyHostDataLogic().RetrieveAll(); gCompany_ID = lCompanyHosts.Where(ch =&gt; ch.hostname.ToLower() == Host.ToLower()).Select(ch =&gt; ch.company_id).FirstOrDefault(); } } return gCompany_ID; } } </code></pre> <p>I am having a hard time understanding why this would be returning Guid Empty for valid hosts after a period of time where it is working normally. My best guess is it has something to do with a period of inactivity on the website that is causing the issue. I am however unsure of the best way to resolve this. </p> <p>Is there something I am missing or would there be a better way to implement this type of functionality?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload