【问题标题】:asp.net global.asax.cs and global.asax differenceasp.net global.asax.cs 和 global.asax 的区别
【发布时间】:2013-04-20 12:34:30
【问题描述】:

我的 global.asax 文件。好像

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)
        {

        }    
    }
}

但是当我查看其他 global.asax 文件时,似乎

<%@ 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>

为什么我的 global.asax 文件与他们不同?我使用 4.0 框架。当我尝试路由时,我的项目看不到我的路由规则。

【问题讨论】:

    标签: asp.net url-routing global-asax


    【解决方案1】:

    您的“Global.asax”实际上是一个“Global.asax.cs”——您的 Global.asax 本身可能看起来像这样:

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

    Global.asax.cs 是所谓的代码隐藏文件。这两种方法在功能上没有真正的区别——代码隐藏只是为了分离标记和服务器端代码之间的关注点而设计的。

    这与您遇到的任何路由问题无关。

    【讨论】:

    • 谢谢,但我有路由问题。我的网页无法访问我的路由并显示此消息“在路由集合中找不到名为 'xxx' 的路由”..我想了一下.可能吗?
    • 你应该用你的完整路由 Global.asax/RegisterRoutes 和你收到的错误的完整堆栈跟踪来更新你的问题。
    猜你喜欢
    • 1970-01-01
    • 2014-05-11
    • 2021-08-02
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多