473,657 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application_Beg inRequest 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.Secu rity
Imports System.Threadin g
Imports System.Globaliz ation
Imports System.Configur ation

Namespace ASPNET.Test

Public Class [Global]
Inherits System.Web.Http Application
Sub Application_Beg inRequest(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_Beg inRequest' 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 8048
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_Beg inReqeust 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_Sta rt(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="globa lcode.cs"
Inherits="globa lcode"%>

=====globalcode .cs========
public partial class globalcode : HttpApplication
{
public globalcode()
{

}

void Application_Beg inRequest(objec t sender, EventArgs e)
{

HttpContext.Cur rent.Response.W rite("<br/>Application_Be ginRequest..... ......
");
}
=============== ========

#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(app lication 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(objec t sender, EventArgs e)
{
Response.Write( "<br/>application class: " +
Context.Applica tionInstance.Ge tType());
}
===========

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_Beg inReqeust 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_Sta rt(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="globa lcode.cs"
Inherits="globa lcode"%>

=====globalcode .cs========
public partial class globalcode : HttpApplication
{
public globalcode()
{

}

void Application_Beg inRequest(objec t sender, EventArgs e)
{

HttpContext.Cur rent.Response.W rite("<br/>Application_Be ginRequest..... ......
");
}
=============== ========

#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(app lication 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(objec t sender, EventArgs e)
{
Response.Write( "<br/>application class: " +
Context.Applica tionInstance.Ge tType());
}
===========

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
4691
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. That I open http://localhost/MainProject/ or
1
1746
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 authenticate and keep folks from hacking the URL. Is there a way to read the CommandArgument and CommandName from the Application_BeginRequest?
3
18329
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 the code below, I get the following error... "System.NullReferenceException: Object reference not set to an instance of an object" ****************************************** protected void Session_Start(Object sender, EventArgs e) { System.Uri...
3
6017
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 this context 2) How can I get the name of the Page being requested from within Application_BeginRequest ? ((System.Web.UI.Page)HttpContext.Current.Handler).ToString() returns "".
7
5216
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 folder are using this code of url rewrite project is running completely fine on localhost but after uploading first page (http://emailware.net.temporary.domain.name/user/index.aspx) is fine but as i click 123 Easy-CD Ripper
0
1412
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 Request. So in my Application_Beginrequest function i am writing a line to the event viewer.I see that for each request my event viewer has 3 entries.
19
3580
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 dynamically, something like: protected void Application_BeginRequest(Object sender, EventArgs e) { if (Session == "True")
3
2672
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 no longer works. They don't support Application_BeginRequest? They've given me a list of the low-level functions they do support, which can be viewed at http://s221042302.websitehome.co.uk/check.aspx
7
2570
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 example: If I call www.mysite.com/UserName. I want to rewrite the UserName part. This works fine in my dev environment but when I publish the site Application_BeginRequest does not get called for this URL. It does however get called for any of the...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.