"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:Oi**************@TK2MSFTNGP06.phx.gbl...
Nope. In VS2005 you can add a Global.asax file, because there isn't one
by default when you add a new Web Site; but there is no code behind page
and no way that I can see of creating one.
I was talking about a Web applications. The Web application is a new project
type in VS 2005. Web sites differ from Web applications.
I've created a new Web site project to see how it handles with a global.asax
and here's what I have found so far:
1. Global.asax cannot be created with the code-behind file. Option to Place
code in separate file is disabled.
2. Global.asax uses a code-inline model
<%@ 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>
By default it has no Application_AuthenticateRequest.
To create it use the dropdowns above the code window. In the Object list (at
right) select the Application, then in the Event list select
AuthenticateRequest. It will add a new event as following
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
3. If you want to use code-behind, delete all the code from Global.asax and
change the Page directive
<%@ Application Codebehind="Global.asax.cs"
Inherits="WebApplication1.Global" Language="C#" %>
Then add a new class file named Global.asax.cs into the App_Code and copy
the code I have sent you yesterday
public class Global : System.Web.HttpApplication
{
.....
}