ASP.NET 2/Global.asax/code-behind/Application_Start

G

Guest

Hi,

I need to get a string from a COM component at application start. (It's a
Long Story and I cannot change this fact.) In ASP.NET 1.1, I simply called
this COM component in Global.asax.cs from Application_Start, stuck the string
in the HttpApplication.Application object and life was good.

However, I've noticed in ASP.NET 2.0 you are not given the opportunity to
create a .cs codebehind file for the Global.asax when you go to ADD NEW
ITEM..., the PLACE CODE IN SEPERATE FILE grayed out. I know I can get around
this by manually creating a Global.asax.cs but I'm worried this is creating
some sort of risk.

A) What is the reason for not allowing a code behind file for Global.asax in
ASP.NET 2.0?

B) What would be the best way for my to get my string out of the COM object
at Application_Start – I do not know how do COM interop from a CODE-INSIDE
file because it seems like you can not add the using statement (as in using
MyCOMobj;)?

Thanks,
Nick
 
B

Brock Allen

You can still handle the Application_Start in the global.asax file. Other
than what file you put this method in, it's the same as before.
 
J

Juan T. Llibre

re:
A) What is the reason for not allowing a code behind file
for Global.asax in ASP.NET 2.0?

Because it's not needed.

Anything you could possibly code in a code-behind file
for global.asax can be coded in global.asax itself.

global.asax is not like .aspx files.
It doesn't have a UI, so you can code directly in it.

Getting rid of code-behind in global.asax corrects an architectural mistake.

re:
at Application_Start - I do not know how do COM interop from a CODE-INSIDE
file because it seems like you can not add the using statement (as in using
MyCOMobj;)?

<%@ Import Namespace="MyCOMobj" %>
<script language="C#" runat="server">

void Application_Start(object sender, EventArgs e) {
// Application startup code goes here
}
</script>
 
J

Juan T. Llibre

You're very much welcome, Nick.

Sometimes it's the little things that trip us,
especially if they are not well documented.

;-)



Juan
=====
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top