473,785 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mapping the Application Path in Web Config

74 New Member
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_En d" 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...wi thout 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 5734
lilOlMe
74 New Member
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_Sta rt(..) 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_Sta rt 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 Recognized Expert Contributor
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 New Member
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
1202
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 great, however, I now have a config file that I need that is located on a virtual mapped path within iis. During my HtppApplication load, I have no HttpContext, hence my problem. How do I map a path when I have no Current Context?
5
310
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 understanding was that ASP.NET was supposed to set itself up, especially as I am using Windows Server 2003. Can anybody give me instruction as to resolution; what folder should I be granting the access to? The path shown only exists as far as the...
4
3093
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 use. The equivalent GUI steps would be, open IIS, select my application->properties, app configuration, in whildcard application mapping type the path to aspnet_isapi.dll. Thanks, Jingmei Li
9
2778
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 wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
6
2099
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 ? -- Michael Tissington http://www.oaklodge.com
2
9912
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 network drive, then moves a specified file to the remote server. I've imported the SDK API "WNetAddConnection2A" to map the network drive.
13
7081
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 with the mapped drive letter, but the drive letter refers to the drive mapping for the user that started the process, and cannot be resolved to a UNC path from a service running under LocalSystem. Presumably, therefore, I need to get the drive...
1
3488
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 relative path (see example below) <storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="..\config\exceptionHandlingConfiguration.config" /> I can edit my configuration with the entlib config tool with no...
0
1745
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 xyz.com/somnath …it will interpret “somnath” as a user name and internally call page show_user.aspx?user=somnath. I have created a HTTP module URLCheckingModule for URL checking. This is settings in my web.config file … <httpModules> <add...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.