ASP.NET MVC Url Route supporting (dot)

Add a UrlRoutingHandler to the web.config. This requires your url to be a bit more specific however (f.e. /Users/john.lee). This forces every url starting with /Users to be treated as a MVC url: <system.webServer> <handlers> <add name=”UrlRoutingHandler” type=”System.Web.Routing.UrlRoutingHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” path=”/Users/*” verb=”GET”/> </handlers> </system.webServer>

Set session variable in Application_BeginRequest

Try AcquireRequestState in Global.asax. Session is available in this event which fires for each request: void Application_AcquireRequestState(object sender, EventArgs e) { // Session is Available here HttpContext context = HttpContext.Current; context.Session[“foo”] = “foo”; } Valamas – Suggested Edit: Used this with MVC 3 successfully and avoids session error. protected void Application_AcquireRequestState(object sender, EventArgs e) { … Read more

Difference between Application_Start and Application_OnStart

In classic (legacy) ASP, there are a handful of special function names that, if defined in your global.asa file, will be run at specified points during the application lifecycle. These are defined as: Application_OnStart – runs once, when your application receives the first HTTP request and immediately before any .ASP files are processed. Application_OnEnd – … Read more

Is it possible to debug Global.asax?

A simple way to break in Application_Start() is to use the System.Diagnostics.Debugger class. You can force the application to break by inserting System.Diagnostics.Debugger.Break() where you would like the debugger to break. void Application_Start(object sender, EventArgs e) { System.Diagnostics.Debugger.Break(); // … }

When to use Application_Start vs Init in Global.asax?

From the MSDN docs: The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance. Init: Called once for every instance of the HttpApplication class after all modules have been created. UPDATE: if you need to … Read more

“Could not load type [Namespace].Global” causing me grief

One situation I’ve encountered which caused this problem is when you specify the platform for a build through “Build Configuration”. If you specify x86 as your build platform, visual studio will automatically assign bin/x86/Debug as your output directory for this project. This is perfectly valid for other project types, except for web applications where ASP.NET … Read more