.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Are same the System.Web.HttpContext.Current.Session and normal Session?

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

Hi all,

I have used System.web.httpcontext.current.session and normal session in my web application

both sessions are having the same name.. but i can get the value from session["name"] not from System.web.httpcontext.current.session["name"]..

is there any problem..

I have used system.web.httpcontext.current.session in my class file..

session have use in my aspx.cs file..

supppose I need to check the session["name"] in my class file what should I do?

is there any diffreence between thease?



View Complete Post

More Related Resource Links

HTTPContext.Current.Session losing the variable sporatically

I have noticed a strange behaviour in my ASP.net 2.0 application. I have some logic in my aspx page that accesses some Session variables fine, then accesses some app_code and most of the time the HTTPContext.Current.Session returns the variable back fine.  However, I have noticed that sometimes this Session returns null, like it has lost it's "pointer" to the current HTTPContext. Is this a known bug, has anyone seen something like this before?   Any help would be appreciated, thanks, Mark. 


Hello, everyone! Well, I made some researches to discover how can I use session variables in App_code. A lot of sites show me answer is use HttpContext.Current.Session. But I´m having following error: The name 'HttpContext' does not exist in the current context. What can I do?

redirectMode="ResponseRewrite" disables HttpContext.Current.Session



we render a nice error page which uses quite a lot of code in the background. I tried adding redirectMode="ResponseRewrite" to the customErrors section in the web.config, but then the framework returns null from HttpContext.Current.Session. Therefore some of our code does not work anymore. When redirectMode is not set or set to ResponseRedirect then HttpContext.Current.Session is set.

How can we circumvent this?



HTTPContext.Current.Session is NULL in SharePoint 2007 (MOSS)


For some strange reason HTTPContext.Current.Session is null in SharePoint 2007 web application.

Session is enabled everywhere and used to work so its not a setup issue. Something got corrupted at some point either via patches or something...

Doing "Reset To Definition" fixes the issue, but I can't do that in production environment and what is reset to definition has to do with session being null?

Searching on the web found a post from someone having same exact issue:


I need to know how to FIX this w/o doing complete "Reset To Definition".

HttpContext.Session A potentially dangerous Request.QueryString value was detected from the client


I have an ashx handler that was working fine in VS2008 but when I upgraded to VS2010 (haven't gone back to VS2008 to double check though) and when I try to grab the value from HttpContext.Request.Params["update"] I get the following error:

+ ex {"A potentially dangerous Request.QueryString value was detected from the client (update=\"<SETIProducts><Produ...\")."} System.Exception {System.Web.HttpRequestValidationException}

"A potentially dangerous Request.QueryString value was detected from the client (update=\"<SETIProducts><Produ...\")."} System.Exception {System.Web.HttpRequestValidationException}

I've read that I can set the validateRequest to false, but I was wondering about the impacts and looking for any other suggestions. 

I know very little about security when it comes to web programming but I thought I should mention that my handler will be running on a internal file server but transmitting data to/from an eCommerce platfo

'Session' does not exist in the current context


In my application I am trying to read and write session variables in a class file using C#.  What do I need to use to access the Session variables?

Get current session timeout value



I have a section in my web app that displays the user's name, the current datetime and a logout link. What i would also like to display is the time left for the session.

Is this possible?

I'm using an ajax timer to give the user the real time, so if i could display also the time that is left for the session to end would be great.

Can anyone help?

How to get current user session in Windows application C#?



I am trying to create a Windows Application similar to facebook friend finder.exe in .NET. The steps I have followed to achieve this is as follows:

1. I have created a webservice containing webmethod SaveContacts(string firstname, string lastname, string number, string photo, string email, string userid).


2. I am consuming the webservice in a Windows Form application and calling the above mentioned function.

Now, I want to get the current logged in user ID which through the windows form application which is something tedious to me.

If anyone have any idea how to achieve this. Please help.






httpcontext session


 Hi, i've one problem with httpcontex.current.session into class.

I've a class  for a shopping cart but if i put one object into my cart from my pc i see the object, but if open browser from another pc i see the always  the object  that i had put with another pc.


I declared httpcontext into global.asax, i've statesession Inproc or StateServer, but the result is same thing

public class ShoppingCart {

    public List<CartItem> Items



   private set;

    public static readonly ShoppingCart Instance;
    static ShoppingCart()

        if (HttpContext.Current.Session["cart"] == null)

            Instance = new ShoppingCart();
            Instance.Items = new List<CartItem>();
            HttpContext.Current.Session["cart"] = Instance;

Killing SQL Server Session as a normal cancelation way in production environment



I have a problem, I'm planning to implement a solution for cancelling queries that could be risky and I need some expert advice. 

I'm using a custom data access .net assembly to execute all queries in the database, and now I've been asked to implement some sort of cancelling functionallity, so if the user press the cancel button, without knowing exactly what query is being executed (usually long lasting queries) it has to be cancelled. I can use the Kill sentence, but the problem is that I need to know which process to kill.

What I'm planning is the following...

As I can control every query executed, I can add a GUID as a comment at the end of each query that could be cancelled, so If the code tries to run the following query "Select top 1000000 from BigTable", I add the comment guid to the sentence ("Select top 1000000 from BigTable --CancelGUID:1234-3456-5678-7890")

Then I provide a method that given a CancelGUID I kill every sql server session that contains that GUID, I get all session with the following sentence:


SELECT req.session_id

FROM sys.dm_exec_requests req

CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

WHERE sqltext.text like '%CancelGUID:1234-3456-5678-7890%' 



And then execute Kill for each session_

ASP.Net 4 Problem with Session - System.Web.SessionState.HttpSessionState


I am building the Tailspin Shopping Cart from the asp.net http://www.asp.net/web-forms 

I am trying to put in this code into a Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using uboPrducts.Data_Access;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace uboPrducts.Classes
    public struct ShoppingCartUpdates
        public int ProductId;
        public int PurchaseQantity;
        public bool RemoveItem;

    public partial class MyShoppingCart
        public const string CartId = "TailSpinSpyWorks_CartID";

        public String GetShoppingCartId()
            if (Session[CartId] == null)
                Session[CartId] = System.Web.HttpContext.Current.Request.IsAuthenticated ? User.Identity.Name : Guid.NewGuid().ToString();
            return Session[CartId].ToString();

I get 4 errors from the above few lines. It says that Session is "The name Session does not exist in the current context"

When I go to the downloaded program and open it (note I

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

SQL Server Session state problem.


Hi to all,

I have some things that I want to know. I am right now using a free asp.net webhosting ("somee.com"). The problem is that when I am visiting a page, there's a tendency that values stored in my session variables are lost. Therefore, it causes an error when the requested page is loaded.

1. I am thinking of using sessionState mode="SqlServer". Will it solve my problem?

Actualy Im working on it but Im having problems when connecting to the sql database.

2.  Is that a problem in the webhost?

3. Do free webhosting sites provide allow session state in the sql server?. Because ive tried it locally into my computer and error say's i should intall the ASP.NET Session State SQL Server version 2.0 or above.

Session and Application Variables


I have a web application in which i need to logout the user if he clicks the logout button or even if he closes his browser window. On Logout button click, i am doing session.Abandon(), but how to go about his browser window close.

Can anybody help with a code sample.

Is there any way to find out the reason for session expiry?


Dear All,

is there any way to find out the reason for session expiry?



Session time out earlyer with in 5 min.


In my live site session time out with in 5 min only.how can i get the default i.e 20 min time . below webconfig file give below

<?xml version="1.0"?>
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, &#xA;        System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, &#xA;        PublicKeyToken=31bf3856ad364e35">
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, &#xA;        System.Web.Extensions, Ver

Datatable in session


I am creating a simple shopping cart using a datatable that is passed into a session object.  I have a small mini cart that displays the total number of items in the cart as well as the running total - this is displayed in a web control.  When the web control starts up I run a try/catch to see if the session object exists, if it doesn't I create the datatable for the cart and store it in the session.  I then have a datalist control that contains all the information for my products including an "add to cart" button.  When the page loads everything looks fine.  If I click on an "add to cart" button nothing happens to the session information.  If I click on it again, the session information updates - displaying only one item is in the cart and then counts up correctly there after.  Additionally, after adding an item, if I select a different item in the list, the same issue occurs.  I am not sure why this is happeing, if anyone can give me an idea I would appreciate it. 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend