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

Accessing the Server Object from a timer started in Global.asax

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 email template).

I am using HttpContext.Current.Server.MapPath to access the Server
object BUT its null, which I guess is correct as the timer is running
in its own thread.

Simple solution, anybody know how to gain access to this object from
within a Timer started from Global.asax

Really appreciate your help with this one, I have searched groups and
the web but obviously putting in the wrong search terms as I am getting
nothing back, or is it that simple?

regards

Richard

Jul 24 '06 #1
2 1881
Well , if you are using Context then it is totally wrong, u cannot access
this HttpContext directly in Global.asax, simply because there is no session
behind it or your are not pointing to any Session, try this thing,

in Global.asax make a function

public void testa()
{
Server.MapPath("ABC");// this wont be null : tested
}

"rgparkins" wrote:
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 email template).

I am using HttpContext.Current.Server.MapPath to access the Server
object BUT its null, which I guess is correct as the timer is running
in its own thread.

Simple solution, anybody know how to gain access to this object from
within a Timer started from Global.asax

Really appreciate your help with this one, I have searched groups and
the web but obviously putting in the wrong search terms as I am getting
nothing back, or is it that simple?

regards

Richard

Jul 24 '06 #2
Hi Murtaza,

Yes I have been playing around and you are obviously right. To get
around this problem I started hard coding som file paths, then
hardcoding some other values at which point it was dawning on me that
this kind of service really needs to be instantiated in a place other
than the Global of the website.

I made the decision after trawling google and finsing advice not to put
these kind of services in the website. Developing a small application
that I will install now.

Thanks for your pointers

Regards

Richard

Murtaza wrote:
Well , if you are using Context then it is totally wrong, u cannot access
this HttpContext directly in Global.asax, simply because there is no session
behind it or your are not pointing to any Session, try this thing,

in Global.asax make a function

public void testa()
{
Server.MapPath("ABC");// this wont be null : tested
}

"rgparkins" wrote:
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 email template).

I am using HttpContext.Current.Server.MapPath to access the Server
object BUT its null, which I guess is correct as the timer is running
in its own thread.

Simple solution, anybody know how to gain access to this object from
within a Timer started from Global.asax

Really appreciate your help with this one, I have searched groups and
the web but obviously putting in the wrong search terms as I am getting
nothing back, or is it that simple?

regards

Richard
Jul 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: [Gauthier] | last post by:
Hello, I've a simple question: On a server that run multiple asp.net HttpApplication, is there any way with the asp.net framework to exchange data between different application? I basically...
2
by: Ekul | last post by:
I have an application that allows users to login and logout. I track how many users are logged in and when each individual is logged in. The application will not allow concurrent logins(let a...
6
by: Antti Laakso | last post by:
Hi i have function like above Public Sub halytystutkinta() Dim ds As New DataSet ds = dl2.HaeHalytys() Dim onkohal As Int16 onkohal = ds.Tables(0).Rows(0).Item("onkohalytys") halid =...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
2
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
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...
7
by: teo | last post by:
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...
6
by: Alex | last post by:
Hello All, I'm having a problem with global.asax file. The session_start method of globals.asax.vb is not firing in my project when I copy the files to a production server. It works OK in my...
10
by: Nemisis | last post by:
Hi everyone, I am trying to create a custom error page, that the user gets shown when a error has occurred within my website. The code works perfectly, apart from when an invalid URL is typed...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.