如何使用cookie在ASP.NET中创建一个愿望列表 [英] How to create a wishlist uisng C# in ASP.NET with cookies

查看:65
本文介绍了如何使用cookie在ASP.NET中创建一个愿望列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是从工作中分配使用Cookie在c#中创建心愿单但我无法弄清楚该怎么做。

我需要用户按下按钮(心形)来添加产品在他的愿望清单中。

任何人都可以帮助我。

请记住我是asp.net中C#的新手。



我尝试过的事情:



这是我的代码,直到现在



Hello, i was assigned from work to create a wishlist in c# using cookies but i cant figure out what to do.
I need a user pressing a button (Heart Shape) to add a product in his wish list.
Can anyone help me.
Keep in mind i am new to C# in asp.net.

What I have tried:

This is my code until now

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_WishListAdd : System.Web.UI.Page
{
    //DataClassesDataContext db = new DataClassesDataContext();

    Product prod = new Product();

    string p_id, p_btitle, p_img, p_desel, p_desen;

    protected void WishAdd(object sender, EventArgs e)
    {

   
        p_id = prod.ProductID.ToString();
        p_btitle = prod.ModelNameEl;
        p_img = prod.ProductImage;
        p_desel = prod.DescriptionEl;
        p_desen = prod.DescriptionEn;

        HttpCookie WishCookies = new HttpCookie("WishCookies");
        WishCookies.Value = prod.ProductID.ToString();
        WishCookies.Expires = DateTime.Now.AddHours(2);
        Response.Cookies.Add(WishCookies);


    }

}

推荐答案

这很简单。对于

A)单个值,请使用 HttpCookie.Value属性(System.Web)| Microsoft Docs [ ^ ]

B)多个值,使用: HttpCookie.Values Property(System.Web)| Microsoft Docs [ ^ ]



It's quite simple. For
A) single value, use HttpCookie.Value Property (System.Web) | Microsoft Docs[^]
B) multiple values, use: HttpCookie.Values Property (System.Web) | Microsoft Docs[^]

HttpCookie WishCookie = new HttpCookie("WishList");
//A)
WishCookie.Value = "Whatever";
//B)
//WishCookie.Values["Val1"] = "1";
//WishCookie.Values["Val2"] = "2";
//WishCookie.Values["Val3"] = "3";
WishCookies.Expires = DateTime.Now.AddHours(2);
Response.Cookies.Add(WishCookie);





祝你好运!



Good luck!


这篇关于如何使用cookie在ASP.NET中创建一个愿望列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆