Global.asax / Global.asax.cs in v2

M

Mark Rae

Hi,

When you create a new web site in VS.NET 2005, it doesn't contain a
Global.asax file by default and, when you add one manually, it creates a
Global.asax file with in-line code e.g.

<%@ Application Language="C#" %>

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
........
</script>

However, when upgrading from v1.x to v2, the Upgrade Wizard keeps the
existing Global.asax and Global.asax.cs files separate e.g.

<%@ Application Inherits="Global" Language="C#" %>

and

using System;

public class Global : System.Web.HttpApplication
{
protected void Application_Start(Object sender, EventArgs e)
{
// Code that runs on application startup
}
........
}

Someone asked me today why that was, since they had always been led to
believe that code-behind was better then in-line code - I didn't have an
answer as to why the default Global.asax file in v2 uses in-line code.

Does anyone know the reason(s) for this? I'd be interested to know if anyone
is using v2 this way. Are there any issues regarding compilation i.e. would
the Global.asax file have to be deployed with the full in-line code, or
would the v2 compiler wrap it into the site's DLL?

Any assistance gratefully received.

Mark
 
K

Karl Seguin [MVP]

There are a bunch of new compilation models in 2.0. One of them allows all
inline code to be precompiled and deployed.

One isn't better than the other. Prior to 2005, there wasn't intellisense
with inline which made codebehind more compelling. I can't tell u why the
upgrade wizard does it one way, but adding the file does it the other way.

To be honest, the best way, especially if you are worried about deploying
source code, is (and always has been) to use HttpModules instead of
global.asax..

Karl
 
M

Mark Rae

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
There are a bunch of new compilation models in 2.0. One of them allows all
inline code to be precompiled and deployed.

Yes indeed.
One isn't better than the other. Prior to 2005, there wasn't intellisense
with inline which made codebehind more compelling. I can't tell u why the
upgrade wizard does it one way, but adding the file does it the other way.

Fair enough.
To be honest, the best way, especially if you are worried about deploying
source code, is (and always has been) to use HttpModules instead of
global.asax..

I'm not particularly worried about it because I never write in-line code.

I've not had much occasion to look at HttpModules, other than this one:
http://www.codeproject.com/aspnet/WebPageSecurity_v2.asp?msg=1494506 which I
use for every web app that needs SSL.

I should look more into HttpModules.
 
J

Juan T. Llibre

re:
I didn't have an answer as to why the default Global.asax file in v2 uses in-line code

Because it saves a compilation step.

Anything you want/need to do in code-behind can be done inline.

Since global.asax has no renderable components,
there's nothing to be gained by using code-behind in it.
 
M

Mark Rae

re:

Because it saves a compilation step.

Really? Doesn't inline code get compiled along with code-behind in v2?
Anything you want/need to do in code-behind can be done inline.
Anything...?

Since global.asax has no renderable components,
there's nothing to be gained by using code-behind in it.

Fair enough, but there's nothing to be lost by using code-behind in it
either, right...?

This is quite interesting:
http://www.dotnetheaven.com/Uploadf...rticleID=7b351622-0b4f-452f-8d2a-651ceba126cd
 
J

Juan T. Llibre

re:
Really? Doesn't inline code get compiled along with code-behind in v2?

Yes. It gets compiled *twice*.

If you use code-behind in global.asax/cs/vb, first the code-behind
script gets compiled, and then global.asax gets compiled.

*That* is the compilation step which is saved by not using code-behind in global.asax.

Why do you think it's convenient for global.asax to be compiled,
and then re-compiled, if there's no renderable code in it ?

re:
Anything...?

Yes, anything.

Can you point to *anything* which can't be done inline
in global.asax which *can* be done in code-behind cs or vb ?

re:
Fair enough, but there's nothing to be lost by using code-behind in it either, right...?

Sure, but why go through the extra effort for no gain ?
 
M

Mark Rae

re:

Yes. It gets compiled *twice*.

If you use code-behind in global.asax/cs/vb, first the code-behind
script gets compiled, and then global.asax gets compiled.

*That* is the compilation step which is saved by not using code-behind in
global.asax.

Fair enough.
Why do you think it's convenient for global.asax to be compiled,
and then re-compiled, if there's no renderable code in it ?

I don't per se...
Can you point to *anything* which can't be done inline
in global.asax which *can* be done in code-behind cs or vb ?

Of course I can't - that's why I asked the question in the first place.
Sure, but why go through the extra effort for no gain ?

No reason, I guess...
 

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

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top