Hello Mike,
Welcome to the MSDN newsgroup.
From your description, I understand you're developing an ASP.NET 2.0/vs
2005 web application and you have manually added a codebehind file for your
application's global.asax component. However, you found the
Application_BeginReqeust handler's code not executed at runtime, correct?
Based on my understanding, as for using codebehind file for global.asax
component in ASP.NET 2.0/vs 2005 application, we need to take care of the
following things:
1. ASP.NET 2.0/VS 2005 by default use inline code model for global.asax,
that means it put the event handlers's code in global.asax file (instead of
a separate code behind). e.g.
===========
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
........................
</script>
============
Therefore, if you want to add codebehind file for global.asax, you can
manually create a source code file(contains the global class), but you also
need to associate this file with the global.asax file.(see #2)
2. To associate the global.asax file with our codebehind class file, you
can use the @Application directive in global.asax file. e.g.
====in global.asax========
<%@ Application Language="C#" CodeFile="globalcode.cs"
Inherits="globalcode"%>
=====globalcode.cs========
public partial class globalcode : HttpApplication
{
public globalcode()
{
}
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.Write("<br/>Application_BeginRequest...........
");
}
=======================
#Note that .net framework 2.0 use partial class to assciate ASP.NET front
page/usercontrol with codebehind, so I define the codebehind class as
partial also(and derived from Httpapplication class).
Also, since I've specified "CodeFile" attribute in global.asax file's "@
Application" directive, we can simply put the codebehind file(globalcode.cs
in this case) in the same folder with global.asax(application root dir).
Thus, at runtime, ASP.NET compiler engine will locate the codebehind
through the directive and attribute setting and compile them together.
As for the problem you encountered, I think it is likely the ASP.NET
runtime doesn't use your global class(for some configuration reason). You
can check the above settings. In addition, we can use the following code
statements in our page's code to detect whethter the ASP.NET application is
using the global.asax (rather than the default HttpAplication class) in our
application:
=============
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<br/>application class: " +
Context.ApplicationInstance.GetType());
}
===========
If the globa.asax is working, the output should be something like:
=-==============
application class: ASP.global_asax
=============
Hope this helps you some. If there is anything else we can help, please
feel free to let me know.
Regards,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)