473,395 Members | 1,987 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,395 software developers and data experts.

Mapping the Application Path in Web Config

74
Hi there,

I'm developing a ASP.NET application using VB.NET as the server side code.

In my application, I have a directory that holds temporary resources for the duration of a user's stay on my website. When the user's session ends my Global.asax "Session_End" function is called and it removes any temporary resources that the user was using.

When I hard code the location of the temporary resource folder I am able to locate the temporary resource folder and do my clean up....and everything works fine.

The problem is that when I move the application to a web server this path will change...and I may have no way of knowing the path to this directory.

I have already tried to access the application's path using Server.MapPath() in my Global.asax but this does not work. (Because it throws an exception that states that "Sever operation is not available in this context")

Currently I'm storing the path to the temporary resource in the Web.Config file's <appSettings> section.

I was wondering if anyone knew how to store the application's path into the web.config...without hard coding in the location?

Or

If anyone knew of a function that works like Server.MapPath that will work in the Global.asax file?


Thanks!

-LilOlMe
Aug 16 '07 #1
3 5708
lilOlMe
74
I solved this problem!

I ended up declaring a Private Shared (static) class variable within the Global.asax file and setting it's value in the Application_Start(..) method using Server.MapPath().
Expand|Select|Wrap|Line Numbers
  1.  TempResPath = Server.MapPath("~/TemporaryResources/")
  2.  
Hope this helps out anyone else stuck on this problem!

What I don't understand is why the Sever methods don't work in the Global.asax file's Session_End...


I understand that you cannot use HttpContext methods in your Session_End event handling method..

This is because no HttpContext object is available at the time this event is fired...
There is no HttpContext object because it is created by ASP.NET during a web request...No web request is made when the Session_End event is fired...this event happens automatically when a SessionID is recycled.

What I don't understand is why the Sever object is not available in the Session_End event...but is available in the Application_Start event.

I'm happy this is all working but I'm still a bit confused.
I'd love it if anyone could share the answer.

:)

-Lilolme
Aug 16 '07 #2
radcaesar
759 Expert 512MB
You can't execute server side code like this.
If you need to execute code, you need to do it in a class, such as your
global class defined in the global.asax file.
Aug 16 '07 #3
lilOlMe
74
You can't execute server side code like this.
If you need to execute code, you need to do it in a class, such as your
global class defined in the global.asax file.
I don't understand what you are trying to tell me.
What do you mean by "You cant execute server side code like this"?


Oh did you mean mapping the application path in the Web.Config?
Yeah I kinda figured it wasn't possible for a bunch of reasons:
-> it's a configuration file...
-> and its an xml file so how could I really expect to do any sort of computations here

I should have changed the title of the question to be "How do you use Server.MapPath in the Global.asax file".

If this isn't what you meant, could you please explain.

Thanks

-lilOlMe
Aug 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Michael McDaniel | last post by:
I have overridden HttpApplication in my class library. When my application starts, There are configuration files that I need to load in order for my application to work correctly. This works...
5
by: Martin Robins | last post by:
I have never dabbled with ASP.NET until now so be warned! I have created a web application with the single default form: WebForm1.aspx and when I try to display it I get this error. My...
4
by: BentleyInc | last post by:
I'm trying to find a way to add a whildcard application mapping to aspnet_isapi.dll in IIS programmatically.... been looking into IIS administrator reference but didn't find the right function to...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
6
by: Michael Tissington | last post by:
I'm trying to add some extensions to IIS on the properties, home directory, config screen. I must be missing something because the OK button is always disabled ... Any ideas please ? --...
2
by: Tomas Vera | last post by:
Hello All, I have a web application that is required to copy a file from the WebServer to a remote web server (staging server to production server). I've created an application that maps the...
13
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I am actually trying to get the UNC path of the main module of a process running from a mapped drive, and I am trying to do this from a service. The ProcessModule class only provides the full path...
1
by: =?Utf-8?B?Uk1C?= | last post by:
I am using the Configuration Application Block, and I want to keep my config files in a folder off of the app root called config. I have modified the app.config to point to the folder with a...
0
by: somnathmali | last post by:
Suppose I have site xyz.com. Site has a page called show_user.aspx where I need to access the Session variables. But this show_user.aspx page will not be called directly Instead , when user type...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.