Does Static Reference To HttpContext.Current.Session Return Same Session For All Users

Feb 4, 2011

Is there room for issue in the following code in terms of multiple users of the same web application? I mean, I know that a purely static string will be shared across all sessions for a single ASP.NET application, but since this explicitly refers to the Current.Session, even though it is static it seems like it would always refer to the session instance of the "current user." But an error is happening that could be explained by everyone sharing the current value of Mode and thus the most recent change overwriting everyone else's mode value. (As a background: This string is in a Helpers class that is used throughout the application. I do not want to make references to Session["Mode"] throughout the application and do not want to have to pass Session["Mode"] in every method call from an aspx.cs page.)

public static string Mode
{
get
{
var value = HttpContext.Current.Session["Mode"];
return (value ?? string.Empty).ToString();
}
set
{
HttpContext.Current.Session["Mode"] = value;
}
}

View 2 Replies


Similar Messages:

Difference Between ControllerContext.HttpContext.Session And HttpContext.Current.Session

Nov 23, 2010

i'm using an example in which i can fake the session.It's for use in a unittest of a mvc controller.In the test i create a controller and then i do this:

FakeHttpContext httpctx = new FakeHttpContext(null,null,null,null,mSessionItems );
ControllerContext ctx2 = new ControllerContext(httpctx,new RouteData(), target);

here mSessionItems is my session and target is my instance of a controller,and indeed, when i'm in a controller reading this.ControllerContext.HttpContext.Session, i have a session, great!but.... i also read the session outside the controller, and there i use HttpContext.Current.Session, and that is null (or actualy, the HttpContext.Current is null).

View 1 Replies

HttpContext.Current.Session Is Null

Aug 20, 2010

I am getting HttpContext.Current.Session is null.Will this be a problem if we have application hosted in web farm.

View 1 Replies

How To Get Session Data With Out Having HttpContext.Current, By SessionID

May 5, 2010

I am searching to find a way to read and write on session data but with out having the HttpContext.Current.Why I won to do that ?, because I wish to make some action with the user Session after the page have been close and unloaded. For example, a user load and see a page, then I create a thread to make some action and let user go. Inside this thread I like to read the session data, but in this case HttpContext.Current is not exist any more.

So is there a way to read Session Data knowing just the session id.I store my session inside an sql server, and I see them... its there on table ASPStateTempSessions . How can I read them "offline" and manipulate them ?

View 2 Replies

MVC :: HttpContext.Current.Session Item Is Null?

Jan 17, 2011

i'm storing in HttpContext.Current.Session current user, SiteUser is single-tone class that presents current active siteuser, and when he logged i'm creating new SiteUser() in controller and in constructor adding him to the session:

[Code]....

then, with every request to the server services i'm check is user available in session:

[Code]....

otherwise i'm generate non-auth-user exception and redirect him to the logon page. but sometimes HttpContext.Current.Session[sessionKey] is null, but HttpContext.Current.Session doesn't null and FormsAuthenticationTicket is available and Expired property is also false. can somebody help me, why HttpContext.Current.Session[sessionKey] can be null?UPDi have downloaded symbol tables of source .NET Framework and set breakpoints at SessionStateItemCollection on changing collection items. and i resolved some mistakes:1) all collection items are null — "culture" is setting up after2) it happens at the session end eventi can't understand how it can be, because at web.config session timeout is set 20

View 20 Replies

C# - Accessing HttpSessionState (HttpContext.Current.Session) From Another Thread?

Nov 25, 2010

We have a web site which implements a central HttpSessionState management in App_Code like this:

[code]...

All of this worked fine ultil we needed to implement a time consuming process in a new thread...
In the second thread HttpContext.Current.Session is null (we know its because the current context its different between threads) so everything fails :

Investigating we found that you could pass the session from one thread to another like this:

[code]...

View 2 Replies

Why HttpContext.Current.Session Is Null In Global.asax

Nov 15, 2010

I'm using VS2010 and created a simple asp. web forms application, using Development Server to test it. I try to store user data - queried from sql server - in the session, since I don't want to access database in every request. I'm using the 'Application_AuthenticateRequest' and the 'Session_Start' methods.

First round:

AuthenticateRequest called. The following code ran:

[Code]....

The _current variable is a private static field published through a static property. In the first round the Session is null, and I think it's ok because the Session_Start not called yet. The Session_Start looks like this:

protected void Session_Start(object sender, EventArgs e)
{
Session["EMPLOYEE_DATA"] = EmployeeFactory.Current;
}

In the next round the Session_Start is not called of course but in the AuthenticateRequest I can't access to the session. The HttpContext.Current.Session is null and the this.Session reference throw a HttpException says the "Session state is not available in this context".

However I can access the Session from any of the page_load events but it's a bad practice I think that I put authentication every page_load.

View 1 Replies

C# - HttpContext.Current.Session.IsNewSession Still True After Redirect?

Feb 18, 2010

I am trying to redirect to the same page with different query string parameters

HttpResponse resp = HttpContext.Current.Response;

resp.Redirect(landingPagePath)

To avoid further processing after redirection i check if

HttpContext.Current.Session.IsNewSession == false

but for some reason i found that this is not always the case after redirection

View 2 Replies

Error While Calling Web Service And Using System.Web.HttpContext.Current.Session

May 5, 2010

I created an AutocompleteExtender web service. I am getting a Object reference not set error in the peice of the code where I am referring to System.Web.HttpContext.Current.Session. Does anyone know why this is. And I am checking to see if it is != null before I reference it. But it crashes. Is there another way to pass another parameter to the web service?

View 2 Replies

HttpContext.Current.Session Is Throwing Exception In Business Class

Sep 8, 2010

In our application we have to access session objects in business class. We are using HttpContext.Current.Session to get the session value. In some cases it returns the value but mostly its throwing a null reference exception(Object reference not set to an instance of an object). We have the following code Try

If HttpContext.Current.Session("Username") IsNot Nothing then
' Statements to be executed
End If
Catch ex As Exception
'Log to db
End Try

Here HttpContext.Current.Session("Username") is mostly throwing an exception "Object reference not set to an instance of an object" While debugging we found that HttpContext.Current itself is nothing.

View 2 Replies

State Management :: HttpContext.current.session Is Null In App_code/.cs File

May 20, 2010

1. SetSession.aspx page sets value for a session variable and redirects to default.aspx page using Response.redirect() code.

2. Default.aspx page tries to create an object of class in app_codecommon.cs file.

3. In app_codeCommon.cs file, I am trying to access the session variable set in step1 using HttpContext.Current.Session object.

but step 3 gives error that object reference not set to an instance. as HttpContext.Current.Session is null.

I surf abt it on net, and seems to be problem with asp.net framework.

View 1 Replies

Share And Connect To Browser Session Of Any Of Current Users

Apr 7, 2010

In my website I am maintaining log of users in which I am storing some user's information such as user machine IP umber,SessionId,UserName etc.and able to show the list of current and past users in webpage. I want to share and connect to browser session of any of the current users. Is it possible,if yes then how?

View 5 Replies

C# - Caching Through HttpContext.Current.Cache Or Just A Static?

Mar 28, 2011

Last night I wrote up my first IHttpModule to do some request processing. I'm using a regular expression to inspect the raw url. The IHttpModule will be called on every request, so it seems reasonable to do some sort of caching of the regular expression object to prevent creation of it on every request.

Now my question... what is better: use the HttpContext.Current.Cache to store the instantiated object or to use a private static Regex in my module?I'm looking forward to the reasons why. Just to clarify: the regex will never change and thus always be the same thing.

View 3 Replies

How To HttpContext.Current Work, Providing Context Appropriate State Off A Static Variable

Mar 31, 2010

I've always wondered how you can access the correct state of the current http context via a static method:

HttpContext.Current.Session["foo"] = "bar";

In any other program, anywhere else, my initial assumption about working with a static accessor like this is that changing it will change it across all threads. Similarly, another thread running my change it on me while I am trying to use it.But HttpContext.Current does not behave like this. It provides the appropriate state for the given request, even through the static accessor.

View 3 Replies

How To Reference A Scriptmanager From HttpContext.Current.CurrentHandler

Mar 28, 2010

I reference the current page in a class with

Page page = HttpContext.Current.CurrentHandler as Page;

I know need to reference ScriptManager1. What the syntax ?

View 2 Replies

Asp.net - HttpContext.Current.Request.Url.AbsolutePath Return An Empty String?

Oct 6, 2010

When user requests http://localhost/WebApp1/Default.aspx, txtApplicationPath.Text should be assigned "/WebApp1", while txtAbsolutePath.Text should be assigned "http://localhost/WebApp1/Default.aspx", but instead both textboxes display empty strings.

[code]...

View 1 Replies

Security :: End Specific Session Outside The Current Session?

May 20, 2010

I would like to check if someone tries to access the application with the same username from a different browser/pc/etc. All usernames and passwords are stored in a MSSQL db.

What I am doing at the moment is: In the global.asax-file in Application_start(..) I initialize [Code]....

Now with every user that logs in I can check whether he is allready in ( in that case, he won't be able to log in, he'll be redirected to the login page ). Let's say it's the same user who wants to login but for some reason he wants to start the application from a different pc, maybe in a different building. Unless he hasn't forget to logout, he won't be able to login on this different computer. So he would has to go back and logout or wait for the timeout.

Now wouldn't it be more convenient to abandon the first session and let the same user login to the pc where he is right now?

The question is, is it possible to end the first session without beeing in it? Or is there any other solution for that problem? Since I have the SessionID stored in Application["UserList"] is there any possibility to end that specific session?

View 3 Replies

State Management :: Users Getting Logged Out Because HttpContext.Current Is Null?

Aug 19, 2010

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users. Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies. In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage sessionAs for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was. This seems to work well for us. It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.What's happening is that certain users are being logged out after just a few minutes. We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out. We do not know why the HttpContext.Current is null, and I understand there are many reasons that may occur. What I'm trying to figure out is, is there any way to re-establish the context once it is null? If not, is there anything I can do at this point other than have the user login again? We're also trying to figure out a better way of managing user information (preferences, roles, flags, history, etc), but everything needs context to use, right? Cookies, sessions, cache, etc. all require a response or request, correct? hope this makes sense, because I really need help with this. I've searched the forums here, and found many posts about HttpContext.Current going null, but not a lot of solutions for this...

View 14 Replies

C# - Is It Safe To Access .net Session Variables Through Static Properties Of A Static Object

May 10, 2010

Is it safe to access asp.net session variables through static properties of a static object?Here is what I mean:

public static class SessionHelper
{
public static int Age
{
get
{
[code]...

Is it possible that userA could access userB's session data this way?

View 2 Replies

MVC :: Access HTTPContext And Session From Custom Base Controller Class?

Jan 13, 2010

I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.

My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.

Am I doing something wrong or need missing something?

My custom base class definition:

public class ApplicationControllerBase : Controller

controllers classes definition:

public class HomeController : ApplicationControllerBase

using ASP.NET MVC 1, .NET 3.5.

UPDATE:

It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.

My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.

View 3 Replies

Security :: HttpContext.Session A Potentially Dangerous Request.QueryString Value Was Detected?

Sep 29, 2010

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}

View 3 Replies

Web Forms :: Store Value Without Session - Static

Jan 21, 2010

I am currently working on asp.net 3.5 with C#. In our application Link buttons are used in Grid to redirect page. means when user click on link from Home Page it will redirect to Job details and when user click on Job details link grid it will redirect to VehicleDetail page. My problem is how to store value on jobDetails page from which page user came. without using Session , Static variable when page is redirect.

View 5 Replies

Web Forms :: How To Access Session In Static Methods

Sep 15, 2010

I write a simple static method in my web page. How can i access session["id"] into method? I dont have access.For example:

public static void myFunc()
{
Session["id"]= 100;
}

View 2 Replies

State Management :: Creating A Static Variable And Adding To Session?

Oct 29, 2010

I am creating a static variable and adding to session.This variable has value that is user specific. Now I am getting a problem with this users are complaining that they are getting values that should be another users. It's like a mix up with session. Could this be because of static variable declaration?

View 2 Replies

C# - Static Behave / Only Work For A Specific User Session Or For Overall Application?

Mar 1, 2011

I have an asp.net application with c# language. I have a common class which maintain the constants and static variables and fields. I also have a login page. If the user logs in successful I set IsLoggedInSuccessfull as a static boolean variable in common class.

My question is: Will this only work for a specific user session or for overall application ?

Edited:
Based on some answers I got another question here.

let say i am using the Static method as Authenticate(User objUser). intention is to call this method when user clicked log in button. where on login button I am let say prepare the User object with certain parameters required for login, then passing to this method. what would be the impact there? let say I have single server for now (no server farm or garden). then there will be the single application level method to authenticate the user, right? and say 10000 user are going to logging in to this site/application then how authenticate() method comes in behaves ? will CLR automatically manage threading there ?

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved