Where is the Global.asax.cs file
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的更多相关文章
- 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 ...
- <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Language="C#" %>
<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Lan ...
- Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer
x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...
- Global.asax.cs介绍
转载 http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...
- C# Global.asax.cs 定时任务
定时执行更新Redis缓存操作 protected void Application_Start(object sender, EventArgs e) { Timer timer = new Tim ...
- Global.asax.cs中相关方法
protected void Session_Start(object sender, EventArgs e) { #if DEBUG //debug 登陆默认设置 #endif } protect ...
- .Global.asax.cs中的方法的含义
Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...
- ASP.NET Global.asax详解
最近在研究bbsmax的代码,但是一直不知道入口在哪里,然后就对各个文件分析了,然后终于在对global.asax文件查看的时候看到Application_BeginRequest才明白入口,所以现在 ...
- ASP.NET Global.asax详解【转】
global.asax是一个文本文件,它提供全局可用代码.这些代码包括应用程序的事件处理程序以及会话事件.方法和静态变量.有时该文件也被称为应用程序文件. global.asax 文件中的任何代码都是 ...
随机推荐
- Python int与string 的转换
string → int 1.10进制的string转化为int int('12') → type(int('12')) 进行验证 2.16进制的string转化为int int('12', 16) ...
- Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法1 - 条件判断法
本文来源于:http://blog.csdn.net/zhubaitian/article/details/39293883 Robotium的测试类ActivityInstrumentationTe ...
- java实现文件上传--flash上传
1.http请求的头信息是“application/octet-stream”,request body 是二进制的flash图片流 2.把流中的信息读入到文件中 代码如下,代码分三个部分: ---- ...
- 11039 - Building designing
Building designing An architect wants to design a very high building. The building will consist o ...
- bzoj1005 [HNOI2008]明明的烦恼
1005: [HNOI2008]明明的烦恼 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3032 Solved: 1209 Description ...
- So you want to be a 2n-aire?[HDU1145]
So you want to be a 2n-aire?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- BZOJ4631 : 踩气球
将所有盒子插入链表,每当一个盒子变空时,从链表里删去它. 查一下它的前驱后继$pre,nxt$,那么$[pre+1,nxt-1]$都是空的. 每次对于$[A,B]$这段都为空,对小朋友按$R$维护线段 ...
- POJ2104 & 主席还是可持久化还是 函数式
题意: 区间第K大. SOL: 非常有意思的树,尽管我搞不清楚名字. 原理参见clj的可持久化数据结构研究. wa了整整一天,然后重打,然后1a... code: /*================ ...
- CF 706B 简单二分,水
1.CF 706B Interesting drink 2.链接:http://codeforces.com/problemset/problem/706/B 3.总结:二分 题意:给出n个数,再给 ...
- FZU1894 单调队列
S - 1019 Time Limit:1500MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...