Login.aspx

                     login.aspx

用户随时都可以通过click the "Sign In" button in the header (_Header.ascx)。

IbuySpy使用的是Forms-based authentication,which is enabled by making a entry in the application's Web.config  file.

有些页面(CheckOut.aspx。。。)必需认证了的用户才能够进入,如何确定该用户是否认证用户呢?
    这些页面并不是在该页中书写代码来验证进入者是否为认证用户。
    它们是在web.config中间设置了进入障碍。
    
        



那么,在这些页面无法进入的情况下,我们会跳转到另外的页面,而跳转到哪个页面也是有web.config来设置的。
在Web.config 中的The loginurl attribute specifies the login page that the application should redirect to any time a user attempts to access an application resource that does not allow anonymous access.

                   
         
       
   

 


在login.aspx页面中:

如果login成功了,那么the LoginBtn_Click event handler performs three important actions: 与代码进行对照。
1,将临时cart中的items转到个人的cart中,这样信息就不会丢失,有助于以后的使用。
    shoppingCart.MigrateCart(tempCartID, customerId);
    实际上,只是将原来购物车的TemperaryID改成了该用户的名字而已。

2,给client一个personalization的cookie,那么在以后进入default.aspx时,能够看到customed personal welcome。
    Response.Cookies["IBuySpy_FullName"].Value = customerDetails.FullName;

3,调用RedirectFromLoginPage() static method ,This is a built-in ASP.NET class。 作用是:这个method发出一个mac的加密的cookie认证ticket到客户端浏览器来确认认证了的客户username。在这个程序中,我们使用Customer ID来作为客户的认证名。在随后的对这个程序的请求中,我们仍然可以使用这个用户名。在发出了认证ticket到客户端浏览器后,这个method即RedirectFromLoginPage()能够使浏览器返回到the login page navigation came from.
(originating page?default.aspx,其实这里的意思是:如果试图进入restricked的页面,同时你还没有login的话,会redirect到login page,而后,回到restricked page,如果是直接点击上面的sign in标签的话,而后,会回到default。page)
    FormsAuthentication.RedirectFromLoginPage(customerId,RememberLogin.Checked);


实际上,用来标志用户身份的CustomerID也就是该用户的ShoppingCartID,用来标志购物车
从这句代码可以看出:
// Migrate any existing shopping cart items into the permanent shopping cart
       shoppingCart.MigrateCart(tempCartID, customerId);


1,CustomerID是由login的用户的用户名和密码确定的:
       IBuySpy.CustomersDB accountSystem = new IBuySpy.CustomersDB();
       String customerId = accountSystem.Login(email.Text, password.Text);

2,ShoppingCartID是由用户名(已登陆)或者TemperaryID决定。
       IBuySpy.ShoppingCartDB shoppingCart = new IBuySpy.ShoppingCartDB();
       String tempCartID = shoppingCart.GetShoppingCartId();
而在现实中,情况的确也是这样:
// If the user is authenticated, use their customerId as a permanent shopping cart id
            if (context.User.Identity.Name != "") {
                return context.User.Identity.Name;
            }

 

我们看到生成了一个personalizationcookie,它是怎么生成的呢?

// Lookup the customer's full account details

ASPNETCommerce.CustomerDetails customerDetails =

accountSystem.GetCustomerDetails(customerId);

 

// Store the user's fullname in a cookie for personalization purposes

Response.Cookies["ASPNETCommerce_FullName"].Value = customerDetails.FullName;

 

// Make the cookie persistent only if the user selects

// "persistent" login checkbox

if (RememberLogin.Checked == true)

{

Response.Cookies["ASPNETCommerce_FullName"].Expires =

DateTime.Now.AddMonths(1);

}

 

如果没有选择Checked == true,那么cookieuser ends the session的时候,就会destory

session&cookie详见ASP.NET

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值