473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Application_BeginRequest does not seem to run

Hi,

I have set up a new web site application in VS 2005, and have created a
couple of pages which seem to run ok.

I then manually added a file called Global.asax.vb, within a folder that I
also manually created 'App_Code' with the start code as below:

Imports System.Security
Imports System.Security.Principal
Imports System.Web.Security
Imports System.Threading
Imports System.Globalization
Imports System.Configuration

Namespace ASPNET.Test

Public Class [Global]
Inherits System.Web.HttpApplication
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)

Try

........
However when I try and debug the application the code on the pages seem to
run ok, but the code within my 'Sub Application_BeginRequest' does not seem
to run.

Have I gone about setting up this file in the wrong way, or is there a
setting I need to change to ensure the whole thing runs as an application and
not as individual pages?

Interestingly when I open up VS 2005 before opening an application /
project, there are several recent projects, some of which have a VS Logo to
the left of them, whilst the project in question doesn't it only has a logo
that looks like a folder - Does this mean that it is not configured proerly
as an application, and therefore doesn't even look for a Global.asax file?
Thanks, Mike.

Jun 30 '06 #1
3 8015
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.)
Jul 3 '06 #2
Steven,

Thank you. You gave the perfect answer, just what I needed!

Not knowing exactly how it worked I just copied the code file and not the
..asax file across from another application.

Thanks for your help. I haven't had much time, but I think it would be
worth my while spending some time going back to learn the basics in .Net!
Cheers, Mike.

"Steven Cheng[MSFT]" wrote:
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.)
Jul 4 '06 #3
Hi Mike,

Thanks for your followup.

I'm glad that those information is of assistance. Also, please always feel
free to post here when there is anything we can help.

Have a good day!

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

Jul 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cynic07 | last post by:
Hi, I hope someone could help me with this problem... First, the context : IIS : v5.1 Framework : v1.1 Language : C# I have a main page (default.aspx) which is my server default page. ...
1
by: Amil | last post by:
I use a LinkButton in a DataList. I want to set the CommandName and CommandArgument for the LinkButton. Then I want to, before the postback, examine them during Application_BeginRequest to...
3
by: Paul Daly (MCP) | last post by:
I'm trying to write a log file that captures the referring url if the request is a new session, and captures a querystring value if the user is browsing between pages on the website. When using...
3
by: JezB | last post by:
1) How can I access my object-oreinted classes from the global.asax Application_BeginRequest event ? I cannot instantiate them from session since it complains : Session state is not available in...
7
by: Ankit Aneja | last post by:
I put the code for url rewrite in my Application_BeginRequest on global.ascx some .aspx pages are in root ,some in folder named admin and some in folder named user aspx pages which are in user...
0
by: Rahul | last post by:
Earlier this evening i posted a question that my debug point is hit several times, But after I published the application. I could significantly see less round trip per request for Application_Begin...
19
by: Mark Rae | last post by:
Hi, Is it possible to have programmatic access to the Page object in Application_BeginRequest, or is it too early in the lifecycle...? E.g. to be able to change a page's MasterPage...
3
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I've used an Application_BeginRequest function in my global.asax page to implement some URL rewriting functionality on our website. However, upon moving it to my host (1&1.co.uk), it...
7
by: Joe | last post by:
I'm trying to use the Application_BeginRequest to re-write the path but it doesn't work on the published site when a non-existing URL is called. This does work fine in my dev environment. For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.