Solved

How can I get HttpContext from a web page?

Posted on 2011-02-11
7
419 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Json POSt to Rest API 4 37
Advice on Xojo as a development tool over VB. 4 39
Windows Media Player 2 14
What namespace do I need to import? 2 0
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!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now