Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2008, 04:26 PM
Authorized User
 
Join Date: Jul 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tapping into cache object

Hi and thanks for taking a moment to read this. I have a simple login page that creates a dataset and cache's it on login. I would then like to take the user to another page that displays the data. (Be it with a form view, data view, it really doesn't matter to me) Below is my code. Is there anyway I can take the Source object (Which is my cache object) and display the data on my updateinfo .aspx ? Any advice would be greatly appreciated.

--Jason








public partial class login : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

DataView Source;

int RowCount;





{

SqlConnection myConnection = new SqlConnection("Server=Jason; database=AddressBook; user id=dummy; password=stupid;");

SqlCommand myCommand = new SqlCommand("Select * From Contacts Where username=@username AND password=@password", myConnection);

myCommand.Parameters.Add("@username", txtUsername.Text);

myCommand.Parameters.Add("@password", txtpassword.Text);

DataSet ds = new DataSet();

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);

myAdapter.Fill(ds, "Contacts");

// Create the Cache object named 'Source'

Source = new DataView(ds.Tables["Contacts"]);

Cache["MyDataSet"] = Source;

RowCount = Source.Table.Rows.Count;

if (RowCount > 0)

{

Response.Redirect("Updateinfo.aspx");

}

else

{

lblError.Visible = true;

}

}
























}


}


 
Old June 8th, 2008, 05:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

To get a value from the cache just access it like any other array:

   Source = (DataView)Cache["MyDataSet"];

HOWEVER!! Using the cache the way you are is big problem. You are using the global cache for user specific data. This will be a major security hole, not to mention that it won't always be accurate. The last user to login in will update the cache with new data. When another user goes to the page that loads this data it will be the data for another user, not theirs. Instead you should be using the Session collection to "cache" data for each user context. Use the cache only for data that is common across users.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
about using cache benordz ASP.NET 2.0 Basics 2 April 25th, 2008 09:19 AM
00Synchronize Distributed Object Cache SQL Ser sarosh Classic ASP Basics 0 June 8th, 2007 11:22 AM
Stop the user tapping Brendan Bartley Access 8 January 10th, 2006 08:44 PM
cache pab006 Classic ASP Basics 3 January 22nd, 2004 05:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.