asp.net global.asax.cs and global.asax difference

拈花ヽ惹草 提交于 2020-02-05 02:33:25

问题


My global.asax file. It seems like

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace xxxx
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }    
    }
}

but when I look others global.asax file seems as

<%@ Application Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Diagnostics" %>

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
}
</script>

why my global.asax file is different from them ? I use 4.0 framework.When I try routing,my project cant see my route rules.


回答1:


Your "Global.asax" is actually a "Global.asax.cs" - your Global.asax itself will probably look something like this:

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

The Global.asax.cs is what's known as a codebehind file. There is no real functional difference between the two approaches - the codebehind is simply designed to separate concerns between markup and server-side code.

This has nothing to do with any routing problems you are having.



来源:https://stackoverflow.com/questions/16120425/asp-net-global-asax-cs-and-global-asax-difference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!