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
Solved

How can I get HttpContext from a web page?

Posted on 2011-02-11
7
421 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
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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