using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace NewCitiZenBasic.TestViews
{
    public partial class TT : UserControl
    {
        public TT()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Making("memberNumber", "kojaedoo");
        }

        private void Making(string key, string value)
        {

//날짜입력설정
            //DateTime expiration = DateTime.Now.AddYears(100);     //현재 날자에 100년을 추가한 날자
            //string cookie = string.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
            string cookie = string.Format("{0}={1};", key, value );
            HtmlPage.Document.SetProperty("Cookie", cookie);
        }

        private string GetCookie(string key)
        {
            string result = string.Empty;
            string[] cookies = HtmlPage.Document.Cookies.Split(';');

            foreach (string cookie in cookies)
            {
                string cookieStr = cookie.Trim();     //문자열 앞뒤로 공백 없애기
                if (cookieStr.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase))  //Key= 과 같은
                {                                                                 //문자가 있을시 true 반환
                    string[] CrackedCookie = cookieStr.Split('=');
                    if (CrackedCookie[0] == key) {

                        result = CrackedCookie[1];
                    }
                }
            }
            return result;
        }

        private void btng_Click(object sender, System.Windows.RoutedEventArgs e)
        {
         // TODO: Add event handler implementation here.\
            MessageBox.Show(GetCookie("memberNumber"));
        }

    }
}

+ Recent posts