構成を変更するのではなく、PreApplicationStartupMethod を使用してコードでアプリケーションの起動時に HttpHandlers を登録できます。コード例 ( Nikhil Kothari のブログ投稿から):
[assembly: PreApplicationStartMethod(typeof(UserTrackerModule), "Register")]
namespace DynamicWebApp.Sample {
public sealed class UserTrackerModule : IHttpModule {
#region Implementation of IHttpModule
void IHttpModule.Dispose() {
}
void IHttpModule.Init(HttpApplication application) {
application.PostAuthenticateRequest += delegate(object sender, EventArgs e) {
IPrincipal user = application.Context.User;
if (user.Identity.IsAuthenticated) {
DateTime activityDate = DateTime.UtcNow;
// TODO: Use user.Identity and activityDate to do
// some interesting tracking
}
};
}
#endregion
public static void Register() {
DynamicHttpApplication.RegisterModule(delegate(HttpApplication app) {
return new UserTrackerModule();
});
}
}
}
Phil Haack の投稿、ASP.NET 4 の 3 つの隠された拡張性の宝石も参照してください。