简体   繁体   中英

passing value from one form to another using code behind files in C#

I am trying to check to see if the value of UserAuthInfo.Current is set when redirecting from the default.aspx page to the profile.aspx page. Below is the code I have on both pages:

DEFAULT.ASPX code snippet

if ((logonHolder.AccountStatus))
{

  UserAuthInfo authInfo = new UserAuthInfo();
  authInfo.UserID = logonHolder.UserID.ToString();
  //strlogon_ID
  authInfo.IsAuthenticated = true;                                
  authInfo.Attributes.Add("logon_ID", logonHolder.UserID);
  authInfo.Attributes.Add("Email", txtEmail.Text);
  authInfo.Attributes.Add("UserType", logonHolder.UserType);
   if (logonHolder.UserType == "A")
   {
     authInfo.Attributes.Add("IsAdmin", "Y");
   }
   else
   {
     authInfo.Attributes.Add("IsAdmin", "N");
   }
   authInfo.Roles.Add(logonHolder.UserType);
   authInfo.Attributes.Add("LastName", logonHolder.LastName);
   authInfo.Attributes.Add("FirstName", logonHolder.FirstName);
   authInfo.Attributes.Add("user_employee_number", logonHolder.EmployeeID);
   authInfo.Attributes.Add("user_id", logonHolder.UserID);
   authInfo.Attributes.Add("SessionGUID", _holderService.CreateSession(strret_code, logonHolder.UserID));

   authInfo.CreateTicket(); 
   Session["Session"] = "Valid";
   authInfo.Attributes.Add("user_login_security", LoginSecurity.Unrestricted);

**if (UserAuthInfo.Current != null && UserAuthInfo.Current.IsAuthenticated)
  {
    Response.Redirect("profile.aspx", false);
  }**

Profile.aspx Page_Load code snippet

if (UserAuthInfo.Current == null || !HttpContext.Current.User.Identity.IsAuthenticated)
{
  Response.Redirect(FormsAuthentication.LoginUrl, true);
  return;
}

When running the code, the value of UserAuthInfo.Current is set on the default.aspx page, but it is always null on the profile.aspx page.

Then use a global class accessible for all pages, Below is the code I have on both pages:

public class MyGlobal
{
static string _variable;
public static string Variable
{
        get
        {
            return _variable;
        }
        set
        {
            _variable= value;
        }
}

and use it so:

MyGlobal.Variable = UserAuthInfo.Curren;


string current = MyGlobal.Variable ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM