1

I'm having an issue with passing an int value among ASP.NET pages. I have a login page, where the user logs in with a username and password, the userid is found in the database and is used to set the value of a variable, which is accessible via a get property, and, if successful, a second page (LoggedIn.aspx) is called via this method:

Server.Transfer("LoggedIn.aspx", true);

In the LoggedIn page, I have this toward the top:

<%@ PreviousPageType VirtualPath="~/AccountLogin.aspx" %>

And the value for userid is stored in a global variable in the constructor:

if (this.PreviousPage != null)
        user = PreviousPage.userid;

And another get property provides access to this variable. This process is repeated to a third page when the user selects a button. The problem I seem to be having and cannot quite figure out is that when the user selects the button on the LoggedIn page, that page seems to reload, so the userid value is set to zero, so the value is useless.

  1. Should I use session state instead (i.e., is it more secure)?
  2. If my approach is adequately secure, how do I get around this problem?
John Saunders
  • 160,644
  • 26
  • 247
  • 397
deadEddie
  • 242
  • 2
  • 8
  • 20

1 Answers1

2

As answered previously:

You can pass values from one page to another by followings..

Response.Redirect
Cookies
Application Variables
HttpContext

Response.Redirect

SET :

Response.Redirect("Defaultaspx?Name=Pandian);

GET :

string Name = Request.QueryString["Name"];

Cookies

SET :

HttpCookie cookName = new HttpCookie("Name");
cookName.Value = "Pandian"; 

GET :

string name = Request.Cookies["Name"].Value;

Application Variables

SET :

Application["Name"] = "pandian";

GET :

string Name = Application["Name"].ToString();

Refer the full content here : Pass values from one to another

Community
  • 1
  • 1
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57