473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Session Management in ASP.Net MVC using SQLServer mode in the SessionState

How Can I Get The Session Value from ASPState Db, Where I Am Storing The Session Details Using Sqlserver Mode.

This is what i have tried to fetch data from ASPState database. But couldn't able to do

Expand|Select|Wrap|Line Numbers
  1. public ActionResult Home()
  2.  {
  3.      ViewBag.Result =Session["username"].ToString();
  4.  
  5.     SqlCommand cmd = new SqlCommand("select SessionId from 
  6.      ASPStateTempSessions", con);
  7.  
  8.     byte[] bytdata = new byte[50];
  9.      con.Open();
  10.      SqlDataReader dr = cmd.ExecuteReader();
  11.      var list = new List<LoginUser>();
  12.      if(dr.HasRows)
  13.      {
  14.          while(dr.Read())
  15.          {
  16.              //obj=dr["SessionId"];
  17.              string obj = dr["SessionId"].ToString();
  18.              bytdata = System.Text.Encoding.UTF8.GetBytes(obj);
  19.              System.IO.MemoryStream ms = new System.IO.MemoryStream(bytdata);
  20.                  BinaryFormatter bin = new BinaryFormatter();
  21.                  //bin.Serialize(ms, bytdata);
  22.                  //list = (List<LoginUser>)bin.Deserialize(ms);
  23.  
  24.                 string session = Convert.ToString(bin.Deserialize(ms));
  25.          }
  26.      }
  27.      ViewBag.Data = list;
  28.      return View();
  29.  }
  30.  


This is what i have configured ion Web.config

Expand|Select|Wrap|Line Numbers
  1. <sessionState mode="SQLServer" customProvider="DefaultSessionProvider">
  2.   <providers>
  3.     <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0,       Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SessionSqlCon" cookieless="false" timeout="10" />
  4.   </providers>
  5. </sessionState>
  6.  
Aug 4 '15 #1
0 2252

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session...
0
by: Shell | last post by:
Hi, 1. We are using SQLServer for storing session information. 2. BPSessionStateDB,aspnetdb were newly created from Visual Studio 2005 command prompt using aspnet_regsql utility. 3....
2
by: Evian Spring | last post by:
We are planning on using "SqlServer" mode for our ASP.NET session state. I know for the classes we store in Session that I need to mark them with the SerializableAttribute as described in this...
0
by: John | last post by:
Hello, We have developed a web application which uses ASP.Net to persist a user's session state in SQLServer mode. The application makes use of this feature in a 2 server web farm, which is...
2
by: Justin | last post by:
Right now, I am managing session state through SQLServer (sessionState mode="SQLServer"). Any time I am accessing session variable, I know there will be roundtrip (server hosting the application...
1
by: Jamie Schatte | last post by:
We have two ASP.NET 2.0 websites, both running on the same production web server. One website uses SQLServer mode for session state with no problems. However, although the other website works great...
2
by: satisharas | last post by:
Hello, I am trying to write a custom session manager in ASP.NET 2.0 using oracle as the backend. I want to know how the session expires in web garden and we are using NLB (a session can be...
3
by: kshssne | last post by:
degisn an app for login and session management using mvc architecture in php
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.