How to dynamically connect web pages in ASP.NET (and update the plugin)?

For regular assemblies, you can use MEF to dynamically load assemblies. If these assemblies require real-time updates, it is recommended that you use AppDomains to host dynamic assemblies (you can probably use the Managed Add-in Framework (MAF)). If updates are necessary, the application is paused, assemblies are updated, and the application is saved.

What about assemblies loaded by ASP.NET that contain this code behind classes? How can I update them without having to restart the main appdomain. Is it possible to place some of my pages in a dynamic application? How would you do that? Can this application distribute login and authentication token so that the user cannot re-enter the system?

thanks

+6
source share
2 answers

MEF does not support AppDomain isolation, so unfortunately, even during recomposition, those assemblies that were previously loaded are still loaded into the main AppDomain application. There are two things in ASP.NET that you need to fight:

  • Any changes to physical files (e.g. .aspx, .cshtml, etc.) or any changes to configuration files (.config) or any changes to the \ bin directory will result in reuse of the application. This is due to two things: file monitoring of pages / configs and monitoring files in the \ bin directory (which is due to the fact that ASP.NET uses shadow copying of files by default - this is recommended).

  • Using MEF in another AppDomain will require a disgusting amount of cross-domain communication, either through serialization or MarshalByRef , which I just don't think will ever be a pure implementation. You don’t know how you will run the instances of BuildProvider used to dynamically compile your pages into another AppDomain.

I wonder if you think too much about it. Starting with IIS6, HTTP.SYS manages the routing of incoming requests to the corresponding website, this is handled at the kernel level. Even if the main application rebooted (due to many reasons why it could), the requests will not be dropped, it simply waits for the queue of a new workflow before sending the request. Of course, from the user's point of view, they may notice some simple expectation of a restart of a new application, but really, how often are you going to make these changes?

Many application development suffer from over-engineering. You can design for each scenario, but it’s really easier to maintain a system that is simple but extensible. In my opinion, the desire to do what you indicated will be classified as excessive. Keep it simple.

+2
source

Using a StateServer session will keep your authentication between repeated application pools (caused by file updates).

For your current question:

  • Create a folder outside of your website that your application pool has access to.
  • Put your new builds there
  • You have a task / thread / web service that reads a folder and loads assemblies into the current application domain.
    • A newer version of the assembly should take precedence when creating an instance.

I think your question says this method does not work? What error do you get ...

0
source

Source: https://habr.com/ru/post/898103/


All Articles