Solved

How can I get HttpContext from a web page?

Posted on 2011-02-11
7
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 3

Assisted Solution

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

Author Comment

by:newbieweb
ID: 34874082
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
ID: 34874110
or if you do not want to import the namespace
do
System.Web.HttpContext...
0
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
LVL 3

Accepted Solution

by:
alokvaria earned 400 total points
ID: 34874417
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
ID: 34874952
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
ID: 34876428
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
ID: 34889472
Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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