Solved

How can I get HttpContext from a web page?

Posted on 2011-02-11
7
418 Views
Last Modified: 2012-05-11
In the Global.Seesion_Start() I add a new value thusly:

 HttpContext.Current.Session[Global.AdminDataStore] = new AdminDataStore(UserLogin, Password);
     
But in the Page_Load() for a web page I can not get InitelliSense to pull up HttpContext.

Can I get this from the EventArgs?  If not, where? I need some way to get this data...

newbieweb

0
Comment
Question by:newbieweb
  • 3
  • 3
7 Comments
 
LVL 3

Assisted Solution

by:alokvaria
alokvaria earned 400 total points
Comment Utility
HttpContext is part of System.Web..Make sure you have that added and declared.
0
 

Author Comment

by:newbieweb
Comment Utility
I think my trouble was related to using Global.Application_Start() to set the Context.Items[] collection. Now I use Global.Session_Start() and the Session[] dictionary is working fine.

I assume when I create an object thusly:

Session[Global.AdminDataStore] = new AdminDataStore(UserLogin, Password);

then I access this page property from the Page_Load(), that I am okay:

        public RDDBAdminDataStore RDDBAdminDataStore
        {
            get
            {
                return (RDDBAdminDataStore)Session[Global.RDDBAdminDataStore];
            }
        }

It's working, but is this the right way to persist data for later use?

Thanks,
newbieweb

0
 
LVL 9

Assisted Solution

by:xav056
xav056 earned 100 total points
Comment Utility
or if you do not want to import the namespace
do
System.Web.HttpContext...
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Accepted Solution

by:
alokvaria earned 400 total points
Comment Utility
Yes that is right way..Session will expire if your application is ideal for more than set value in your web.config..
Application start and Session start are two different thing..
If you need a variable which you are going to share across all the sessions than you use application variable..
Say for example your application variable value is 0 and one user open your application in browser and set a value of your application variable to 5 and than other user open the application he will get 5 and not 0...
Well session is for per browser session...So every session your variable value will not be shared..

Hope this help..
0
 

Author Comment

by:newbieweb
Comment Utility
I see both of these work fine:

HttpContext.Current.Session["var"] ...
Session["var"] ...

I need this value to persist for many pages, but will be filling it on Global.Session_Start()

Will both work the same in that case? Why is one better than the other?

0
 
LVL 3

Assisted Solution

by:alokvaria
alokvaria earned 400 total points
Comment Utility
Both are same..
Check below articale out:
http://msdn.microsoft.com/en-us/library/sf0df423(v=vs.80).aspx
0
 

Author Closing Comment

by:newbieweb
Comment Utility
Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now