Application_start and session_start still used?

J

Joe Befumo

I just created the default personal site project in Visual Studio 2005, and it worked perfectly -- very nice.

Next, I'd like to import some stat-capture code that I have working in a Visual Studio 2003 asp,net project.

The first think I noticed is that in the 2003 project, there's a global.asax and a global.asax.vb file, with the code being in the latter. Since the 2005 project had a routine directly in the global.asax file, I moved it to my imported global.asax.vb file. In global.asax I put a line like so:

<%@ Application Codebehind="Global.asax.vb" Inherits="PersonalSite.Global"%>

where PersonalSite is the name of my new project (paralleling what was in my 2003 project).

I get several build errors:

Could not load type 'PersonalSite.Global', in global.asax,

and one indicating the Global is not valid as an indentifier, for

Public Class Global

in Global.asax.vb.

I also noticed that there were no session_start, application_start, etc., procedures in the automatically-created project.

Are these procedures no longer used? If so, where would one put code that must run when the session or application starts and ends?

Thanks.

Joe
 
J

Juan T. Llibre

re:
<%@ Application Codebehind="Global.asax.vb" Inherits="PersonalSite.Global"%>

In ASP.NET 2.0, codebehind and compilewith changes to codefile
Classname changes to Inherits

So, that line should be:

<%@ Application Codefile="Global.asax.vb" Inherits="PersonalSite.Global"%>

Also, if you're using codebehind, you need to use partial classes :

In webform1.aspx.cs:

public partial class WebForm1 : System.Web.UI.Page {}

See : Changes for Beta 2 :

http://msdn.microsoft.com/asp.net/beta2/beta2update.aspx






I just created the default personal site project in Visual Studio 2005, and it worked perfectly --
very nice.

Next, I'd like to import some stat-capture code that I have working in a Visual Studio 2003 asp,net
project.

The first think I noticed is that in the 2003 project, there's a global.asax and a global.asax.vb
file, with the code being in the latter. Since the 2005 project had a routine directly in the
global.asax file, I moved it to my imported global.asax.vb file. In global.asax I put a line like
so:

<%@ Application Codebehind="Global.asax.vb" Inherits="PersonalSite.Global"%>

where PersonalSite is the name of my new project (paralleling what was in my 2003 project).

I get several build errors:

Could not load type 'PersonalSite.Global', in global.asax,

and one indicating the Global is not valid as an indentifier, for

Public Class Global

in Global.asax.vb.

I also noticed that there were no session_start, application_start, etc., procedures in the
automatically-created project.

Are these procedures no longer used? If so, where would one put code that must run when the session
or application starts and ends?

Thanks.

Joe
 
J

Joe Befumo

Okay, I got it so it will compile by putting everything into the global.asax file. Problem is, the application_start sub doesn't seem to be firing. I can set breakpoints in application_start and session_start -- the session_start is reached, but not the application_start. Any advice would be appreciated.

Joe

I just created the default personal site project in Visual Studio 2005, and it worked perfectly -- very nice.

Next, I'd like to import some stat-capture code that I have working in a Visual Studio 2003 asp,net project.

The first think I noticed is that in the 2003 project, there's a global.asax and a global.asax.vb file, with the code being in the latter. Since the 2005 project had a routine directly in the global.asax file, I moved it to my imported global.asax.vb file. In global.asax I put a line like so:

<%@ Application Codebehind="Global.asax.vb" Inherits="PersonalSite.Global"%>

where PersonalSite is the name of my new project (paralleling what was in my 2003 project).

I get several build errors:

Could not load type 'PersonalSite.Global', in global.asax,

and one indicating the Global is not valid as an indentifier, for

Public Class Global

in Global.asax.vb.

I also noticed that there were no session_start, application_start, etc., procedures in the automatically-created project.

Are these procedures no longer used? If so, where would one put code that must run when the session or application starts and ends?

Thanks.

Joe
 
C

caffienerush

Make a copy of your VS 2003 project and open it up in VS 2005.
VS2005 will convert the project to ASP.NET 2.0 and then you can see for
yourself what the new syntax looks like.
I know that all the session and application events are still in use
within ASP.NET 2.0.

Regards.
 
J

Joe Befumo

Thanks all -- I got it working (though I'm not sure how) -- just copied routines to the global.asax one by one, running between each. Pretty strange.

Joe

I just created the default personal site project in Visual Studio 2005, and it worked perfectly -- very nice.

Next, I'd like to import some stat-capture code that I have working in a Visual Studio 2003 asp,net project.

The first think I noticed is that in the 2003 project, there's a global.asax and a global.asax.vb file, with the code being in the latter. Since the 2005 project had a routine directly in the global.asax file, I moved it to my imported global.asax.vb file. In global.asax I put a line like so:

<%@ Application Codebehind="Global.asax.vb" Inherits="PersonalSite.Global"%>

where PersonalSite is the name of my new project (paralleling what was in my 2003 project).

I get several build errors:

Could not load type 'PersonalSite.Global', in global.asax,

and one indicating the Global is not valid as an indentifier, for

Public Class Global

in Global.asax.vb.

I also noticed that there were no session_start, application_start, etc., procedures in the automatically-created project.

Are these procedures no longer used? If so, where would one put code that must run when the session or application starts and ends?

Thanks.

Joe
 
J

Joe Befumo

I wound up getting this to work putting all the code directly in the
global.asax file, rather than in the global.asax.vb. My question now is
whether there are performance implications to doing this? To be honest I'm
still not totally clear on the whole dot.net architecture.

Thanks again,

Joe
 
J

Juan T. Llibre

Hi, Joe, thanks for the feedback.
I'm glad you were able to work around that.

re:
I wound up getting this to work putting all the code directly in the global.asax file, rather than
in the global.asax.vb. My question now is whether there are performance implications to doing
this?

No performance implications at all.

In fact, the default for VS 2005 is not to use code-behind in global.asax,
even though, if you want to use code-behind, you can.

Global.asax is compiled at Request time, not at Deployment time,
so not using codebehind saves a compilation step.

See : http://msdn.microsoft.com/msdnmag/issues/06/01/ExtremeASPNET/default.aspx?fig=true#fig6

Here's the deal : global.asax has no user interface ( UI ),
so there's no use compiling codebehind to MSIL, only to have it be recompiled again.

Anything which you can do in global.asax codebehind,
you can also do in global.asax itself, so why go the extra compilation step ?

See http://msdn.microsoft.com/msdnmag/issues/06/01/ExtremeASPNET/default.aspx
for Frtiz Onion's good backgrounder on ASP.NET 2.0's compilation model,
and its differences with the ASP.NET 1.1 compilation model.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top