By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

Global.asax / Global.asax.cs in v2

P: n/a
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
May 23 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:eC**************@TK2MSFTNGP05.phx.gbl...
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

May 23 '06 #2

P: n/a
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
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/We...sp?msg=1494506 which I
use for every web app that needs SSL.

I should look more into HttpModules.
May 23 '06 #3

P: n/a
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.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:eC**************@TK2MSFTNGP05.phx.gbl... 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

May 23 '06 #4

P: n/a
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:eo****************@TK2MSFTNGP05.phx.gbl...
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.


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/Uploadfi...a-651ceba126cd
May 23 '06 #5

P: n/a
re:
Because it saves a compilation step. 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 you want/need to do in code-behind can be done inline.

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 ?

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:O$**************@TK2MSFTNGP03.phx.gbl... "Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:eo****************@TK2MSFTNGP05.phx.gbl...
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.


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/Uploadfi...a-651ceba126cd

May 23 '06 #6

P: n/a
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
re:
Because it saves a compilation step. 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.


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...
May 23 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.