哪里的Global.asax.cs文件? [英] Where is the Global.asax.cs file?
问题描述
我使用VS 2008我从文件 - >新建 - >网站 - 创建一个新的Asp.net网站项目> Asp.net网站。
I am using VS 2008. I have created a new Asp.net web site project from File->New->Website->Asp.net Website.
现在我想添加在Global.asax还有.cs文件到项目中。所以,我右键单击项目 - >添加新用品 - >全局应用程序类。然后我点击添加按钮。
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.
Global.asax文件得到了添加了内容,在
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>
这是好的。但如果是的Global.asax.cs文件?
This is fine. But where is the Global.asax.cs file?
感谢
推荐答案
这是因为你创建了一个网站,而不是一个Web应用程序。 CS / VB
文件可以看出,只有在Web应用程序,但在网站上不能有单独的 CS / VB
文件
That's because you created a Web Site instead of a Web Application. cs/vb
file can be seen only in Web Application but in website you can't have separate cs/vb
file.
编辑:在网站上你可以添加像CS文件的行为。
In the website you can add 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()
{
}
}
}
这篇关于哪里的Global.asax.cs文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!