Reputation: 21088
Is it possible to embed the Global.asax
file into an assembly? Currently it is represented as a file in the web root directory. But I want to store it as a resource in an assembly.
Upvotes: 1
Views: 850
Reputation: 463
Yes you can. You have three options as far as I know:
.
using System.Web;
using System.Web.UI;
[assembly: PreApplicationStartMethod(typeof(MyAssembly.MyHttpApplication), nameof(MyAssembly.MyHttpApplication.Application_Register)]
namespace MyAssembly
{
public class MyHttpApplication : HttpApplication
{
public static void Application_Register()
{
PageParser.DefaultApplicationBaseType = typeof(MyHttpApplication);
}
protected void Application_Start()
{
// TODO: Your application startup magic :)
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
// TODO:
}
}
}
Trace (or something like that):
Hope that helps :)
Upvotes: 1
Reputation: 23078
Ali Reza Dehdar
's answer is correct (just change Compile
to Embedded Resource
in file's properties) and the result can be seen using a decompiler:
Upvotes: 1
Reputation: 2351
I'm not sure. Have you tried setting Build Action to Embedded Resource? You can do that by selecting the global.asax file and then the option should appear in your property window.
Upvotes: 2