views:

951

answers:

4

Normally I create web application projects and use code-behind, but I have a requirement to create an small throwaway demo app using code-inline.

I added a global.asax file to the app, but for some odd reason, Visual Studio 2008 SP1 won't let me edit any of the code between the script tags i.e. add code to the event handlers such as Application_Start, Session_Start. VS does however let me edit outside the script tags.

This is just a simple file based web app using the built in web server.

Any ideas what's going on?

This is the code-inline global.asax VS creates:

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

Cheers
Kev

A: 

The only time I ever saw this kind of of thing is when I am in debug mode, and I didn't realize it. Seems pretty basic, but have you checked that?

John Sonmez
No code is running, it's just a plain bare bones project with Default.aspx, Global.asax and web.config. I haven't even hit the play button yet.
Kev
+1  A: 

I don't think VS allows inline script in Global.asax. You need to put the code in Global.asax.cs instead.

Kevin Tighe
A: 

tried right-clicking -> view code?

shaunf
I'm actually sitting looking at the code. See update to my question.
Kev
+6  A: 

Ok, so here is the answer:

You can see part of the explanation here and here.

Basically the global.asax file doesn't actually get compiled, so VS2008 put in a fix to prevent you from modifying it, since your modifications will have no effect.

John Sonmez
Fab...I was googling for 'can't edit global.asax' etc and there wasn't even a hint of either of those articles.
Kev