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

Discussion in 'ASP .Net' started by =?Utf-8?B?Tm9OaWNrbmFtZQ==?=, Nov 9, 2005.

  1. 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
     
    =?Utf-8?B?Tm9OaWNrbmFtZQ==?=, Nov 9, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Tm9OaWNrbmFtZQ==?=

    Brock Allen Guest

    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.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > 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,
    > Nic
     
    Brock Allen, Nov 9, 2005
    #2
    1. Advertising

  3. 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>




    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "NoNickname" <> wrote in message
    news:...
    > 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
     
    Juan T. Llibre, Nov 9, 2005
    #3
  4. Thanks, Juan.

    I did not know about Import Namespace. That did the trick.



    Nick
     
    =?Utf-8?B?Tm9OaWNrbmFtZQ==?=, Nov 9, 2005
    #4
  5. You're very much welcome, Nick.

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

    ;-)



    Juan
    =====
    "NoNickname" <> wrote in message
    news:...
    > Thanks, Juan.
    >
    > I did not know about Import Namespace. That did the trick.
    > Nick
     
    Juan T. Llibre, Nov 9, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max
    Replies:
    5
    Views:
    20,921
    liliancho
    Dec 7, 2011
  2. Bob Johnson
    Replies:
    4
    Views:
    1,013
    George Durzi
    Nov 13, 2003
  3. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    846
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,172
    Mark Rae
    May 23, 2006
  5. NoNickname
    Replies:
    2
    Views:
    284
    Bob Barrows [MVP]
    Nov 9, 2005
Loading...

Share This Page