Global.asax or web.config

Discussion in 'ASP .Net' started by hansiman, Jun 18, 2004.

  1. hansiman

    hansiman Guest

    I use Application_Start in global.asax to set some physical folder
    paths ie.:
    Application("pdf") = "c:\www\<site>\pdf\"

    global.asax uses code behind.

    When I move the project from the dev to the production server the
    global.asax code behind is compiled into the project.dll (i guess).

    This renders the physical paths unusable (naturally). Coming from
    classic asp I thought I could just have a dev. and a production
    global.asax.

    Can I make the global.asax "not code behind"? Or should I use
    web.config to store the paths instead? (a question of best practise, I
    guess).

    /morten
     
    hansiman, Jun 18, 2004
    #1
    1. Advertising

  2. hansiman

    Mythran Guest

    I'd use the web.config.


    Also, why use absolute paths? You can get the same result by using the
    following:

    Application("pdf") = MapPathSecure("/<site>/pdf") OR
    Application("pdf") = MapPathSecure(Request.ApplicationPath & "/pdf")

    In your scenario, would this not benefit you? If it does, you wouldn't need
    separate configuration files. If you do it in Global.asax, then you would use
    Server.MapPath("/pdf"). If you use the web.config file, you would use the
    following in your page code-behind:

    EXAMPLE IN FORM_LOAD:

    Sub Form_Load(...) ...
    Application("pdf") =
    MapPathSecure(System.Configuration.ConfigurationSettings.AppSettings.Item("pdf"))
    End Sub

    OR BOTH

    Using global.asax AND web.config :)

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    Application("pdf") = MapPathSecure( _
    System.Configuration.ConfigurationSettings.AppSettings.Item("pdf") _
    )
    End Sub

    BY USING BOTH, you have the advantage of the code loading only once (at
    application start), the value is stored in a plain-text file that you can modify
    to your hearts desire, and you do not have to re-compile if you change the paths
    to the pdf folder :)

    Hope it helps :)

    Mythran



    "hansiman" <> wrote in message
    news:...
    > I use Application_Start in global.asax to set some physical folder
    > paths ie.:
    > Application("pdf") = "c:\www\<site>\pdf\"
    >
    > global.asax uses code behind.
    >
    > When I move the project from the dev to the production server the
    > global.asax code behind is compiled into the project.dll (i guess).
    >
    > This renders the physical paths unusable (naturally). Coming from
    > classic asp I thought I could just have a dev. and a production
    > global.asax.
    >
    > Can I make the global.asax "not code behind"? Or should I use
    > web.config to store the paths instead? (a question of best practise, I
    > guess).
    >
    > /morten
     
    Mythran, Jun 18, 2004
    #2
    1. Advertising

  3. hansiman

    hansiman Guest

    Ahhh. Off course. Why did I stick the the physical path...???...
    thanks a lot.

    but how do I use MapPathSecure in the global.asax file I get a "name
    not declared" when I build and have:
    Application(MapPathSecure(Request.ApplicationPath) & "\pdf")
    in the global.asax file (its the MapPathSecure part that trickers the
    error (it works fine in a standard aspx file).

    /Morten


    On Thu, 17 Jun 2004 17:02:20 -0700, "Mythran" <>
    wrote:

    >I'd use the web.config.
    >
    >
    >Also, why use absolute paths? You can get the same result by using the
    >following:
    >
    >Application("pdf") = MapPathSecure("/<site>/pdf") OR
    >Application("pdf") = MapPathSecure(Request.ApplicationPath & "/pdf")
    >
    >In your scenario, would this not benefit you? If it does, you wouldn't need
    >separate configuration files. If you do it in Global.asax, then you would use
    >Server.MapPath("/pdf"). If you use the web.config file, you would use the
    >following in your page code-behind:
    >
    >EXAMPLE IN FORM_LOAD:
    >
    >Sub Form_Load(...) ...
    > Application("pdf") =
    >MapPathSecure(System.Configuration.ConfigurationSettings.AppSettings.Item("pdf"))
    >End Sub
    >
    >OR BOTH
    >
    >Using global.asax AND web.config :)
    >
    >Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    > Application("pdf") = MapPathSecure( _
    > System.Configuration.ConfigurationSettings.AppSettings.Item("pdf") _
    > )
    >End Sub
    >
    >BY USING BOTH, you have the advantage of the code loading only once (at
    >application start), the value is stored in a plain-text file that you can modify
    >to your hearts desire, and you do not have to re-compile if you change the paths
    >to the pdf folder :)
    >
    >Hope it helps :)
    >
    >Mythran
    >
    >
    >
    >"hansiman" <> wrote in message
    >news:...
    >> I use Application_Start in global.asax to set some physical folder
    >> paths ie.:
    >> Application("pdf") = "c:\www\<site>\pdf\"
    >>
    >> global.asax uses code behind.
    >>
    >> When I move the project from the dev to the production server the
    >> global.asax code behind is compiled into the project.dll (i guess).
    >>
    >> This renders the physical paths unusable (naturally). Coming from
    >> classic asp I thought I could just have a dev. and a production
    >> global.asax.
    >>
    >> Can I make the global.asax "not code behind"? Or should I use
    >> web.config to store the paths instead? (a question of best practise, I
    >> guess).
    >>
    >> /morten

    >
     
    hansiman, Jun 18, 2004
    #3
  4. hansiman

    Mythran Guest

    Woops :p Use, instead of MapPathSecure(), Server.MapPath() if you use it in the
    global.asax :p

    Sorry about that.

    Mythran

    "hansiman" <> wrote in message
    news:...
    > Ahhh. Off course. Why did I stick the the physical path...???...
    > thanks a lot.
    >
    > but how do I use MapPathSecure in the global.asax file I get a "name
    > not declared" when I build and have:
    > Application(MapPathSecure(Request.ApplicationPath) & "\pdf")
    > in the global.asax file (its the MapPathSecure part that trickers the
    > error (it works fine in a standard aspx file).
    >
    > /Morten
    >
    >
    > On Thu, 17 Jun 2004 17:02:20 -0700, "Mythran" <>
    > wrote:
    >
    > >I'd use the web.config.
    > >
    > >
    > >Also, why use absolute paths? You can get the same result by using the
    > >following:
    > >
    > >Application("pdf") = MapPathSecure("/<site>/pdf") OR
    > >Application("pdf") = MapPathSecure(Request.ApplicationPath & "/pdf")
    > >
    > >In your scenario, would this not benefit you? If it does, you wouldn't need
    > >separate configuration files. If you do it in Global.asax, then you would use
    > >Server.MapPath("/pdf"). If you use the web.config file, you would use the
    > >following in your page code-behind:
    > >
    > >EXAMPLE IN FORM_LOAD:
    > >
    > >Sub Form_Load(...) ...
    > > Application("pdf") =

    >
    >MapPathSecure(System.Configuration.ConfigurationSettings.AppSettings.Item("pdf")

    )
    > >End Sub
    > >
    > >OR BOTH
    > >
    > >Using global.asax AND web.config :)
    > >
    > >Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    > > Application("pdf") = MapPathSecure( _
    > > System.Configuration.ConfigurationSettings.AppSettings.Item("pdf") _
    > > )
    > >End Sub
    > >
    > >BY USING BOTH, you have the advantage of the code loading only once (at
    > >application start), the value is stored in a plain-text file that you can

    modify
    > >to your hearts desire, and you do not have to re-compile if you change the

    paths
    > >to the pdf folder :)
    > >
    > >Hope it helps :)
    > >
    > >Mythran
    > >
    > >
    > >
    > >"hansiman" <> wrote in message
    > >news:...
    > >> I use Application_Start in global.asax to set some physical folder
    > >> paths ie.:
    > >> Application("pdf") = "c:\www\<site>\pdf\"
    > >>
    > >> global.asax uses code behind.
    > >>
    > >> When I move the project from the dev to the production server the
    > >> global.asax code behind is compiled into the project.dll (i guess).
    > >>
    > >> This renders the physical paths unusable (naturally). Coming from
    > >> classic asp I thought I could just have a dev. and a production
    > >> global.asax.
    > >>
    > >> Can I make the global.asax "not code behind"? Or should I use
    > >> web.config to store the paths instead? (a question of best practise, I
    > >> guess).
    > >>
    > >> /morten

    > >

    >
     
    Mythran, Jun 18, 2004
    #4
    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. Brian Henry

    web.config and global.asax

    Brian Henry, Oct 26, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    344
    Alvin Bruney
    Oct 28, 2003
  2. Ruslan
    Replies:
    6
    Views:
    461
    Ruslan
    Dec 16, 2003
  3. D. Shane Fowlkes
    Replies:
    2
    Views:
    5,934
    Jeremy
    Jan 12, 2004
  4. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

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

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,168
    Mark Rae
    May 23, 2006
Loading...

Share This Page