I don't have a Global Application class code-behind any more inside my installed templates. All I have is Global.asax. I find more comfortable working with Global.asax.cs.
The Global. asax, also known as the ASP.NET application file, is located in the root directory of an ASP.NET application. This file contains code that is executed in response to application-level and session-level events raised by ASP.NET or by HTTP modules.
How to add global. asax file: Select Website >>Add New Item (or Project >> Add New Item if you're using the Visual Studio web project model) and choose the Global Application Class template. After you have added the global.
The Global. asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event. The file in Listing 1 contains the default Global. asax file for an ASP.NET MVC application.
That's because you created a Web Site instead of a Web Application. I would recommend you using a precomipled Web Application model but if you need to use a Web Site you could do the following:
~/Global.asax
:
<%@ Application CodeFile="Global.asax.cs" Inherits="AppName.MyApplication" Language="C#" %>
~/Global.asax.cs
:
namespace AppName
{
public partial class MyApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
}
}
}
Now reopen your site in VS.
Yes @Darin's Answer is right, the cs/vb file can be seen in the Web Application but in the website you can't have a separate cs/vb file.
Global.asax doesn't have a cs file, but you can write code....
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With