Reputation: 6562
I have a base web ui project, I also have other 'plugin' projects which are just other mvc web applications.
I take the dll's and views from them and toss them into my main web ui's bin and views folder so they can just be added or removed at any time which does work.
each 'plugin' contains a GET method that is called from the main web ui to load the menu options from each of the 'plugins'.
After each URL is called, the main web ui fires the `Session_Start'
menu.Append(HelperMethods.GetModuleMenuHTML(controller, SecurityController.CurrentDomain()));
public static string GetModuleMenuHTML(string controllerName, string currentDomain)
{
string html = string.Empty;
try
{
//THIS LINE HERE IS CAUSING Session_Start to fire again
//IN THE MAIN WEB UI
html = new WebClient().DownloadString(string.Format("{0}/{1}/GetMenu", currentDomain, controllerName));
}
catch (Exception ex)
{
}
return html;
}
What is causing Session_Start to fire when calling html = new WebClient().DownloadString(string.Format("{0}/{1}/GetMenu", currentDomain, controllerName));
and how can I prevent that from happening?
Does this have something to do with me just dropping in the dll and views from another project directly into the main web ui projects as a "plugin" (which does however load correctly into my UI) to be easily added and removed?
Upvotes: 1
Views: 1385
Reputation: 541
The WebClient request is recursively starting a new session. As a hack, you could modify your Session_Start() to check if the incoming url is /{controller}/GetMenu and simply avoid the WebClient call. See: https://stackoverflow.com/a/18656561.
Otherwise, perhaps decorating your MenuController with SessionStateAttribute (https://msdn.microsoft.com/en-us/library/system.web.mvc.sessionstateattribute(v=vs.118).aspx) might avoid the Session_Start altogether (if GetMenu() doesn't use the session state).
Upvotes: 1
Reputation: 2031
Its mainly because of this:
html = new WebClient().DownloadString(string.Format("{0}/{1}/GetMenu", currentDomain, controllerName));
This line uses WebClient class to get the html, but the WebClient class is stateless, and each time its called it uses another request with no cookies, so the server thinks it a new request, and starts a new session.
Upvotes: 1