469,909 Members | 1,562 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

Global.asax or web.config

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
Nov 18 '05 #1
3 5925
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.ConfigurationSe ttings.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.AppSett ings.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" <ha***@hotmail.com> wrote in message
news:10********************************@4ax.com...
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

Nov 18 '05 #2
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" <ki********@hotmail.com>
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.ConfigurationS ettings.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.AppSett ings.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" <ha***@hotmail.com> wrote in message
news:10********************************@4ax.com.. .
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


Nov 18 '05 #3
Woops :P Use, instead of MapPathSecure(), Server.MapPath() if you use it in the
global.asax :P

Sorry about that.

Mythran

"hansiman" <ha***@hotmail.com> wrote in message
news:3j********************************@4ax.com...
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" <ki********@hotmail.com>
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.ConfigurationS ettings.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.AppSett ings.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 modifyto your hearts desire, and you do not have to re-compile if you change the pathsto the pdf folder :)

Hope it helps :)

Mythran

"hansiman" <ha***@hotmail.com> wrote in message
news:10********************************@4ax.com.. .
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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark | last post: by
6 posts views Thread by Andrea Williams | last post: by
22 posts views Thread by fd123456 | last post: by
12 posts views Thread by John M | last post: by
8 posts views Thread by Vishwanathan Raman | last post: by
1 post views Thread by Anonieko | last post: by
1 post views Thread by teo | last post: by
5 posts views Thread by Eric Layman | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.