2

I'm a web developer who's working in a new shop with developers from a desktop background - as such they have certain idiosyncrasies/best practices when it comes to organizing their code - one of which is that separate UI views are isolated into different projects.

So, on the web side of the house, I have a problem with different projects building in different app domains:

1) I have a "portal" project with a default.aspx In the code behind there is a custom authentication method called from inside the Login_Authenticate event to log into the "business layer" of the desktop application. The business side stores session data in ASP.NET sessions.

2) I have a "viewer" project with default.aspx - this was originally in the portal project as "Viewer.aspx", where it was covered under the same login scheme and authenticated fine, but we decided it would be good to stand on it's own project because it is a separate view.

We added the same machine key to both web.config files so the .NET forms authentication could be passed via single sign on.

I built the viewer project in two different the fashions:

1st Try (it's own URL):

http://localhost/Viewer

2nd Try (a subdomain under the portal URL):

http://localhost/Portal/Viewer

The issue I'm running into is that the session is not being passed between the Portal project and the Viewer project. I know this is because IIS is running them in different app domains. Unfortunately without the ASP.NET session from the Portal, the Viewer is not logged into the business application.

Is there a best practice/is it even possible for running multiple projects in one app domain? Should the Viewer be a part of the Portal application since it requires the same session? Should the Viewer be a separate project that requires it's own separate login into the business layer? Is there even a best practice/guideline for this scenario?

Warren J Thompson
  • 408
  • 1
  • 7
  • 19
  • https://stackoverflow.com/questions/55350815/how-to-configure-single-app-domain-to-two-applications please check this and know me the solution – Nivedita Dahima Mar 26 '19 at 06:13

2 Answers2

4

By default session cannot be shared between different applications.

In practice most projects are not separated this way. In my experience most use some sort of n-tier architecture. Basically you have all your "view" code in one asp.net project, any buisness logic/data objects in another dll project, and your data access in a third dll project. The website then just references the other two dlls.

To solve your issue this answer might give you what you want: Sharing sessions across applications using the ASP.NET Session State Service

Community
  • 1
  • 1
Paul Lemke
  • 5,494
  • 3
  • 47
  • 66
  • Right - that's the approach I follow. What they (the desktop/winform devs) want is for me to build the viewer.aspx page in a separate project and then deploy it to the portal app domain via xcopy. I was hoping to have a pretty concrete reason for them as to why this was considered bad practice. – Warren J Thompson May 01 '12 at 04:32
  • The joys of programming is you can architect a "terrible" system but it still might work. In your case you have a "terrible" architecture but there are ways to make it work. Creating a completely different project for every view you have would become a maintenance nightmare! I'd suggest looking at some open source projects to see how they do it. – Paul Lemke May 01 '12 at 14:01
  • They can deploy to the same app domain by using xcopy to manually copy the files over - this was proven in a previous web project they did by hand. The big question is should we - and if not - why not? – Warren J Thompson May 01 '12 at 16:26
  • 1
    I can't give you a concrete example of "why not". The framework supports it, so it's fine. I could see examples of things that are dependent on each other not being deployed together. Or not in the right order. Actually... that's a good point. You would be tightly coupled with something that could change one way or another for no good reason. – Paul Lemke May 01 '12 at 16:42
  • 1
    You can have an inheritance tree 20 levels deep too, "the framework (and paradigm) support it", that doesn't mean you should do it, nor does it make it 'fine'. The same applies here, IMO. – Marcel Valdez Orozco Sep 25 '12 at 01:41
0

There is a way to have multiple projects, but one site. That example is a little old but still works, and is how we do our site.

Darren Kopp
  • 76,581
  • 9
  • 79
  • 93