I need to use the 'Server.MapPath ' function
in the 'Session_End' event of the Global.asax file
(to reach a folder and the clean some temporary files up),
but it doesn't work:
Sub Session_End(ByV al sender As Object, ByVal e As EventArgs)
Dim myPath As String = (Server.MapPath ("../public/MyFolder/")
End Sub
Note:
when I precompile the app,
the Global.asax file will be inserted in the BIN folder
(and not in the usual root folder)
so it may be a further problem
Any idea? 7 6237
Is the public director a level above the root? You may try creating a path
relative to the root for the mappath. If public is above the root, you could
then try:
Server.MapPath( "../" & Request.Applica tionPath & "/public/MyFolder/")
Request.Applica tionPath will return the name for the virtual root so it
won't be pinned on the local directory as much. Are you sure thought that
it's the global.asax that's being created in the bin and not just the dll
for the Global.asax file?
A couple other things to keep in mind. If the sessionstate is not set to
inproc, then the on_end event is ignored. Also, not all functions are
available in the on_end event. It is mainly there to cleanup session
variables and not necessarily to perform other cleanup tasks. For example,
classic ASP developers often tried to run database operations in the on_end
event but database calls weren't allowed during on_end.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"teo" <te*@inwind.itw rote in message
news:hg******** *************** *********@4ax.c om...
>I need to use the 'Server.MapPath ' function
in the 'Session_End' event of the Global.asax file
(to reach a folder and the clean some temporary files up),
but it doesn't work:
Sub Session_End(ByV al sender As Object, ByVal e As EventArgs)
Dim myPath As String = (Server.MapPath ("../public/MyFolder/")
End Sub
Note:
when I precompile the app,
the Global.asax file will be inserted in the BIN folder
(and not in the usual root folder)
so it may be a further problem
Any idea?
Mark,
I tried
the 'public' folder is here www.mySite.it/public/myFolder
and
my .aspx page folder is here www.mySite.it/PersonalApp/Default.aspx
also
the InProc is set on
unfortunately
'Server.MapPath ' and 'Request.Applic ationPath'
from the Session_End
both return an empty string
- - -
Because Server.MapPath on the Session_Start does work ,
I tried to store the resulting string in a variable
to use it in the Session_End ,
but it seems that
the Global.asax file manages variable differently from usual
and it 'looses' its content
and nothing arrives in the Session_End event
- - -
I 'm stumped
(I'm performing my tasks
on the Session_ Start event,
but I don't like it because it consumes time)
From Stephen Walter's "ASP.NET Unleashed" :
Within an ASP.NET page, the Page object is the default object.
In many cases, if you do not specify an object when you call a method or access a property,
you are implicitly calling the method or accessing the property from the Page object.
For example, when you call the MapPath method (which maps virtual paths to physical paths),
you are actually calling the Page.MapPath method. Or, when you access the Cache property,
you are implicitly accessing the Page.Cache property.
The Global.asax file does not have the Page object as its default object.
This means that you cannot simply call a method such as MapPath and expect it to work.
Fortunately, in most cases, you can use a simple workaround.
Instead of calling the MapPath method, you can call the Context.MapPath method.
Or, instead of accessing the Page.Cache object, you can access the Context.Cache object.
If a familiar property or method does not work in the Global.asax file,
you should immediately try calling the method or property by using the Context object instead.
Try it.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"teo" <te*@inwind.itw rote in message news:l3******** *************** *********@4ax.c om...
Mark,
I tried
the 'public' folder is here www.mySite.it/public/myFolder
and
my .aspx page folder is here www.mySite.it/PersonalApp/Default.aspx
also
the InProc is set on
unfortunately
'Server.MapPath ' and 'Request.Applic ationPath'
from the Session_End
both return an empty string
- - -
Because Server.MapPath on the Session_Start does work ,
I tried to store the resulting string in a variable
to use it in the Session_End ,
but it seems that
the Global.asax file manages variable differently from usual
and it 'looses' its content
and nothing arrives in the Session_End event
- - -
I 'm stumped
(I'm performing my tasks
on the Session_ Start event,
but I don't like it because it consumes time)
MapPath translates a relative path based on the current url to an
absolute path. When Session_End is called it's based on a timer and
not a request, so there is no current path from which MapPath can
calculate a relative path.
Perhaps Path.Combine and Assembly.CodeBa se can be used in your
situation.
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Sun, 10 Dec 2006 17:55:29 +0100, teo <te*@inwind.itw rote:
>I need to use the 'Server.MapPath ' function in the 'Session_End' event of the Global.asax file (to reach a folder and the clean some temporary files up),
but it doesn't work:
Sub Session_End(ByV al sender As Object, ByVal e As EventArgs)
Dim myPath As String = (Server.MapPath ("../public/MyFolder/") End Sub
Note: when I precompile the app, the Global.asax file will be inserted in the BIN folder (and not in the usual root folder) so it may be a further problem
Any idea?
>Fortunately, in most cases, you can use a simple workaround.
>Instead of calling the MapPath method, you can call the Context.MapPath method. Or, instead of accessing the Page.Cache object, you can access the Context.Cache object.
I tried,
maybe I always adopted a wrong syntax,
but I always saw the blu irregular underline
under my syntax;
I tried:
Context.MapPath
HttpContext
HttpApplication
and several other namespaces,
but always got the blu irregular underline
(and the app never started)
Do you know the exact fully namespaced syntax?
Session_OnEnd ( or Session_End ) does not support the Request, Response or Server objects.
The only built-in objects you can use are Session and Application.
So, instead of using a Server.MapPath directive in Session_End,
store the fully qualified path in an Application variable.
You'll have no problem using an Application variable
in Session _End, provided Session_End fires at all.
There's many circumstances in which Session_End does not fire.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"teo" <te*@inwind.itw rote in message news:7r******** *************** *********@4ax.c om...
Fortunately, in most cases, you can use a simple workaround. Instead of calling the MapPath method, you can call the Context.MapPath method. Or, instead of accessing the Page.Cache object, you can access the Context.Cache object.
I tried,
maybe I always adopted a wrong syntax,
but I always saw the blu irregular underline
under my syntax;
I tried:
Context.MapPath
HttpContext
HttpApplication
and several other namespaces,
but always got the blu irregular underline
(and the app never started)
Do you know the exact fully namespaced syntax?
On Sun, 10 Dec 2006 17:55:29 +0100, teo <te*@inwind.itw rote:
>I need to use the 'Server.MapPath ' function in the 'Session_End' event of the Global.asax file (to reach a folder and the clean some temporary files up),
but it doesn't work:
Sub Session_End(ByV al sender As Object, ByVal e As EventArgs)
Dim myPath As String = (Server.MapPath ("../public/MyFolder/") End Sub
I found a workaround:
because Server.MapPath does work on the Session_Start event,
I retrieve it in this event, store it in a module variable,
and then use this variable in the Session_End event,
but, important thing:
the variable has not to be declared as Dim myVariable
because it will not work,
but it has to be declared has Shared myVariable This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Lamey |
last post by:
Hi All,
I have the following code but for some reason I cannot get the Session_OnEnd
event to fire.
I am trying to limit the amount of connections a browser session can have.
Where the application is a virtual directory.
Any ideas?
------------
|
by: Steve |
last post by:
I am trying to call a file delete function from inside Session_End in
Global.asax.cs. However, everytime I step into my delete function from
Session_End it jumps to the catch statement and I get the "Object
reference not set to an instance of an object." I don't understand why
it is happening. I would appreciate any help, thanks.
...
|
by: Sebastiano |
last post by:
I want to use Server.MapPath function in Global.asax because I want to save
in an application variable the path of my database. Global.asax is in the
root directory of my web folder and database is in database/database.mdb.
Now, if I start my web site from default.aspx in the root folder all is ok,
but if start it with a page in a nested...
|
by: hansiman |
last post by:
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...
|
by: Rick Hein |
last post by:
I've got a problem with an app I've been working on, the Caching object and
events not firing correctly. In a nutshell: When I'm debugging, and I set a
breakpoint in the removed item call back, the code works correctly. If there
is no debugger it doesn't fire, which causes the app to have problems.
Here's what the code does: The...
| |
by: rgparkins |
last post by:
Hi Guys
Maybe a simple and easy solution to this, but I keep getting exception
object not set to instance etc etc.
I have a Timer that is initiated in Application_Start in Global.asax.
This timer I am using as a service every 10 minutes to send email to
users. OK so all is fine until I need to load a file from the server
(in fact an...
|
by: Michael |
last post by:
Hi
I have a problem related to global.asax and the Server.Mappath-Method.
I collect all unhandled errors in the Application_Error in
Global.asax.
According to the type of error I redirect/transfer the user to the
correct error page.
DataException --~/DBError.aspx
|
by: Yehia A.Salam |
last post by:
Hello,
I was trying to connect to an Xml database, and I thought of loading the Xml
Document in "Application_Start" so that the xml is loaded only once and then
queried later as many times as requested, this should the efficient way of
connecting to the database afaik, however I can't access the xml object in
my aspx files with this error...
|
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= |
last post by:
Hi. I am trying to maintain a list of people who are currently "online" in
SQL. I do this by adding a simple entry to a simple PeopleOnline table
whenever someone logs in to my site.
If they manually log OUT of the site, I have no problem deleting them from
the PeopleOnline table. But if they just close the browser, I was assuming
I'd have...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |