FormsAuthentication

这段代码展示了一个用户登录处理的方法 ProcessLogin。它接收用户 ID 和密码,调用账户业务逻辑层进行登录操作。若登录成功,将用户信息存入会话并根据来源页面进行重定向;若失败则返回 false。

 public bool ProcessLogin(string userId, string password){

   // Use the account business logic layer to login
   Account account = new Account();
   AccountInfo myAccountInfo = account.SignIn(userId, password);

   //If login is successful then store the state in session and redirect
   if (myAccountInfo != null) {
    HttpContext.Current.Session[ACCOUNT_KEY] = myAccountInfo;
    
    // Determine where to redirect the user back too
    // If they came in from the home page, take them to a similar page
    if (FormsAuthentication.GetRedirectUrl(userId, false).EndsWith(URL_DEFAULT)) {

     FormsAuthentication.SetAuthCookie(userId, false);
     HttpContext.Current.Response.Redirect(URL_ACCOUNTSIGNIN, true);

    }else{
     // Take the customer back to where the came from
     FormsAuthentication.SetAuthCookie(userId, false);

     HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(userId, false), true);
    }

    return true;
   
   }else {
    // Login has failed so return false
    return false;
   }
  }

转载于:https://www.cnblogs.com/lifz/archive/2005/08/31/227067.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值