电子商务购物栏,用Cookie怎么做?

bullion 2003-11-16 05:08:34
我想用Cookie实现购物栏的功能,但就是想不出思路来,请做过电子商务的朋友给我讲讲,谢谢了!

最好能给个例子!
...全文
57 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bullion 2003-11-17
  • 打赏
  • 举报
回复
谢谢了!
lanyahuhu 2003-11-17
  • 打赏
  • 举报
回复
up
jpyc 2003-11-17
  • 打赏
  • 举报
回复
购物栏用session做,quickstart里有一个例子,很好,又简单,但说明的问题很详细
bruce007 2003-11-16
  • 打赏
  • 举报
回复
redbb(. Dotneter .) 的思路是首先把用户的登陆信息都保存到session中。 当然登陆时他把用户的相关信息都取到了那个 AccountInfo 中, 包括那个什么FavouriteCategory 都取道了AccountInfo中, 保存到session中去了, 当有需要用户的信息时, 就到session中去读:
AccountInfo myAccount = (AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY]; 当然在读session, cache这类东西时都要判断读出的冬冬是不是为空, 是空的话,就说明用户的信息在session中没有了, 需要他重新登陆
bullion 2003-11-16
  • 打赏
  • 举报
回复
大家给点例子吧!
bullion 2003-11-16
  • 打赏
  • 举报
回复
to redbb(. Dotneter .)
能讲讲原理吗
elite2018 2003-11-16
  • 打赏
  • 举报
回复
use session

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;
}
}

public bool CreateAccount(AccountInfo newAccountInfo){

try {
// Creata a new business logic tier
Account account = new Account();

// Call the insert method
account.Insert(newAccountInfo);

// Store the data in session state and store the authenticated cookie
HttpContext.Current.Session[ACCOUNT_KEY] = newAccountInfo;
FormsAuthentication.SetAuthCookie(newAccountInfo.UserId, false);

//Finally forward to the welcome page
HttpContext.Current.Response.Redirect(URL_ACCOUNTCREATE, true);


}catch {
return false;
}

return true;
}

/// <summary>
/// A method to process an updated account
/// </summary>
/// <param name="updatedAccountInfo">Updated account information</param>
public void UpdateAccount(AccountInfo updatedAccountInfo){

// Create the business logic tier
Account account = new Account();

// Call the udpate method
account.Update(updatedAccountInfo);

//Store the update info back in session state
HttpContext.Current.Session[ACCOUNT_KEY] = updatedAccountInfo;

//Redirect the user to the my account page
HttpContext.Current.Response.Redirect(URL_ACCOUNTUPDATE, true);

}

/// <summary>
/// Retrieves the account information for a customer who has already logged in
/// The method assume the account information is in session state
/// If it can't find it the function will direct the user to login
/// </summary>
/// <returns>The account info for the currently logged in user</returns>
public AccountInfo GetAccountInfo(bool required){
AccountInfo myAccount = (AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY];

if (myAccount == null){
if(required){
HttpContext.Current.Response.Redirect(URL_SIGNIN, true);

}
return null;
}else{
return myAccount;
}
}

/// <summary>
/// Retrieves favourtie category of a customer if we know who they are
/// The method assume the account information is in session state
/// </summary>
/// <returns>The customers favourite category</returns>
public string GetFavouriteCategory(){

AccountInfo myAccount = (AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY];

if (myAccount != null && myAccount.IsShowFavorites) {
return myAccount.Category;
}else{
return null;
}
}

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧