Global.asax or web.config

H

hansiman

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
 
M

Mythran

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
 
H

hansiman

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
 
M

Mythran

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

Sorry about that.

Mythran
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top