当前位置:K88软件开发文章中心编程语言.NET.NET02 → 文章内容

vs2005下Global.asax缺少cs文件的解决方法

减小字体 增大字体 作者:佚名  来源:翔宇亭IT乐园  发布时间:2019-1-3 0:48:56

:2011-03-03 20:45:44

VS2005中发现Global.ascx没有cs文件,所有程序都需要写在一个文件,下面给出一个具体的解决方法:

通过在App_Code文件夹下创建一个类Global.cs,同时该类使用partial修饰且继承System.Web.HttpApplication。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Global 的摘要说明
/// </summary>
public partial class Global : System.Web.HttpApplication
{
#region 默认构造函数
public Global()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion

 

void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
}

void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
}

void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
}

void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
}

void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
}

}

然后Global.asax继承该类即可

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



vs2005下Global.asax缺少cs文件的解决方法