Can Global.asax use CodeBehind Mode in .net 2.0 ,I try it as follow,but failed.

Last post 03-06-2006 9:15 AM by wirelessben. 2 replies.

Sort Posts:

  • Can Global.asax use CodeBehind Mode in .net 2.0 ,I try it as follow,but failed.

    11-21-2005, 5:28 AM
    • Member
      155 point Member
    • idiot
    • Member since 06-24-2002, 11:39 PM
    • Canada
    • Posts 31

    I try it as fllow ,but when I build the project, It's show error  "Error 1 Could not load type 'Global'. E:\wwwsite\dotnet20\Global.asax 1 "
    how can I do it?

    Global.asax
    <%@ Application Language="C#" CodeBehind="Global.asa" Inherits="Global" %>

    Global.asax.cs

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Web;
    using System.Web.SessionState;
    using System.IO;
    /// <summary>
    /// Summary description for Global
    /// </summary>
    public partial 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

        }

        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.

        }
    }

  • Re: Can Global.asax use CodeBehind Mode in .net 2.0 ,I try it as follow,but failed.

    11-21-2005, 9:49 AM
    • Contributor
      6,539 point Contributor
    • bitmask
    • Member since 07-29-2003, 3:18 PM
    • Citizen of the Earth
    • Posts 1,229

    One way to do this is to take the source code you have in your post and put it in a .cs file in App_Code. Then the global.asax only needs the following directive:

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

    Scott
    http://www.OdeToCode.com/blogs/scott/
  • Re: Can Global.asax use CodeBehind Mode in .net 2.0 ,I try it as follow,but failed.

    03-06-2006, 9:15 AM
    • Member
      15 point Member
    • wirelessben
    • Member since 02-19-2003, 3:44 AM
    • Posts 3
    What about the new Web Application Project? It stores the global.asax on the root as in ASP.NET 1.1. This method does not seem to work.
Page 1 of 1 (3 items)