Is adding / removing HttpModules and HttpHandlers at runtime from a website a good idea ? I am looking at ways to make my website as dynamic as possible without uploading changed content all over again. Something like config files. Rule engines exist, but learning them seems like a pain. I might be wrong in my perspective. Please suggest possible ways to change logic in the code at runtime.
Asked
Active
Viewed 2,874 times
3 Answers
7
ASP.NET 4 provides a PreApplicationStartMethod capability that can be used to add HttpModules programmatically.
I just did a blog post on that at http://www.nikhilk.net/Config-Free-HttpModule-Registration.aspx.
The basic idea is you create a derived HttpApplication that provides ability to add HttpModules dynamically at startup time, and it then initializes them into the pipeline whenever each HttpApplication instance is created within the app-domain.
Nikhil Kothari
- 5,215
- 2
- 22
- 28
5
For .NET4 and above:
For dynamically installing a HttpHandler, you need to create a HttpModule wrapper to do that. See the answer to: Any way to add HttpHandler programmatically in .NET?
To dynamically add a http module:
Install-Package Microsoft.Web.Infrastructure
Install-Package WebActivator
[assembly: PreApplicationStartMethod(typeof(MyPreStartClass), "Start")]
namespace .....
{
public static class MyPreStartClass
{
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(FooHttpModule));
}
}
}
Community
- 1
- 1
Chris Marisic
- 32,487
- 24
- 164
- 258