473,378 Members | 1,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 6100
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
I have two projects - they both need to use the same web.config file, the same global.asax file, and share a common "look and feel" via several user controls. Is there an easy way for two...
6
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? ...
22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
12
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
1
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are...
8
by: Doug | last post by:
Visual Studio 2005, SQL Server 2000, ASP.NET/VB.NET Not allowed to use the ASPNET machine account in SQL Server (very strict environment). Need to use Windows authentication, so we use...
1
by: teo | last post by:
I put some variables in a web.config file I have a global.asax file that needs to use one of those variables How can global.asax read that value? If I have more than one web.config ...
5
by: Eric Layman | last post by:
Hi everyone, Currently Im using Global.asax.vb to capture any errors and to send them via email to me. But I didn't get any emails when I purposely crash the web application. May I know what...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.