Solved

How can I get HttpContext from a web page?

Posted on 2011-02-11
7
420 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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