I am using VS 2008. I have created a new Asp.net web site project from File->New->Website->Asp.net Website.

Now I want to add the Global.asax as well as the .cs file to the project. So I Right click on the project ->Add New Item->Global Application Class. Then I clicked on the add button.

The Global.asax file got added with the content as under

<%@ Application Language="C#" %>

 <script runat="server"%>

    void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup } void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown } void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs } void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started } void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised. } </script>

This is fine. But where is the Global.asax.cs file?

Thanks

2 Answers

That's because you created a Web Site instead of a Web Application. The cs/vb files can only be seen in a Web Application, but in a website you can't have a separate cs/vb file.

Edit: In the website you can add a cs file behavior like..

<%@ Application CodeFile="Global.asax.cs" Inherits="ApplicationName.MyApplication" Language="C#" %>

~/Global.asax.cs:

namespace ApplicationName
{
public partial class MyApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
}
}
}

It don't create normally; you need to add it by yourself.

After adding Global.asax by

  • Right clicking your website -> Add New Item -> Global Application Class -> Add

You need to add a class

  • Right clicking App_Code -> Add New Item -> Class -> name it Global.cs -> Add

Inherit the newly generated by System.Web.HttpApplication and copy all the method createdGlobal.asax to Global.cs and also add an inherit attribute to the Global.asax file.

Your Global.asax will look like this: -

<%@ Application Language="C#" Inherits="Global" %>

Your Global.cs in App_Code will look like this: -

public class Global : System.Web.HttpApplication
{
public Global()
{
//
// TODO: Add constructor logic here
//
} void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup }
/// Many other events like begin request...e.t.c, e.t.c
}

Orignal LinkUrl:http://stackoverflow.com/questions/6288209/where-is-the-global-asax-cs-file

Where is the Global.asax.cs file的更多相关文章

  1. ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global" Language="C#" %>

    ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global&q ...

  2. <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Language="C#" %>

    <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Lan ...

  3. Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer

    x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...

  4. Global.asax.cs介绍

    转载  http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...

  5. C# Global.asax.cs 定时任务

    定时执行更新Redis缓存操作 protected void Application_Start(object sender, EventArgs e) { Timer timer = new Tim ...

  6. Global.asax.cs中相关方法

    protected void Session_Start(object sender, EventArgs e) { #if DEBUG //debug 登陆默认设置 #endif } protect ...

  7. .Global.asax.cs中的方法的含义

    Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...

  8. ASP.NET Global.asax详解

    最近在研究bbsmax的代码,但是一直不知道入口在哪里,然后就对各个文件分析了,然后终于在对global.asax文件查看的时候看到Application_BeginRequest才明白入口,所以现在 ...

  9. ASP.NET Global.asax详解【转】

    global.asax是一个文本文件,它提供全局可用代码.这些代码包括应用程序的事件处理程序以及会话事件.方法和静态变量.有时该文件也被称为应用程序文件. global.asax 文件中的任何代码都是 ...

随机推荐

  1. header元素

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. nav元素

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. iOS学习13之OC NSString类

    C语言中,字符串是有char(ASC||码)字符组成. OC中,字符串是由unichar(Unicode)字符组成. 1.字符串(NSString) NSString:不可变字符串,即:创建以后,内容 ...

  4. BZOJ3072 : [Pa2012]Two Cakes

    考虑DP,设$f[i][j]$表示考虑了$a[1..i]$和$b[1..j]$的最小代价. 若$a[i]==b[j]$,则$f[i][j]=\min(f[i-1][j],f[i][j-1])+1$. ...

  5. Jaxb 解析 带有继承关系的bean与xml

    具体方法: 1. 在jaxb的setClasstobebounds中,只需要子类的class,无需父类. 2. 父类的前面加如下声明: @XmlAccessorType(XmlAccessType.F ...

  6. background-attachment 定义背景图片随滚动轴的移动方式

  7. AJAX 跨域请求 - JSONP获取JSON数据

    Asynchronous JavaScript and XML (Ajax ) 是驱动新一代 Web 站点(流行术语为 Web 2.0 站点)的关键技术.Ajax 允许在不干扰 Web 应用程序的显示 ...

  8. Flash与JS之间相互调用以及参数传递

    [AS3]ExternalInterface.call传多个参数的写法代码示例 import flash.text.TextField; ; ; var result:uint = ExternalI ...

  9. linux文本操作界面 vi面板如何复制一行

    linux文本操作界面 vi面板如何复制一行 1)把光标移动到要复制的行上2)按yy3)把光标移动到要复制的位置4)按p 在vi里如何复制一行中间的几个字符?如果你要从光标处开始复制 4 个字符,则先 ...

  10. Maven进价:Maven的生命周期阶段

    一.Maven的生命周期 Maven的生命周期就是对所有的构建过程进行抽象和统一.包含了项目的清理.初始化.编译.测试.打包.集成测试.验证.部署和站点生成等几乎所有的构建步骤. Maven的生命周期 ...