当前位置: 首页>>代码示例>>C#>>正文


C# HttpCookie类代码示例

本文整理汇总了C#中HttpCookie的典型用法代码示例。如果您正苦于以下问题:C# HttpCookie类的具体用法?C# HttpCookie怎么用?C# HttpCookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpCookie类属于命名空间,在下文中一共展示了HttpCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Prijava_OnClick

    protected void Prijava_OnClick(object sender, ImageClickEventArgs e)
    {
        Korisnici korisnik = korisniciService.PrijaviKorisnikaPoKorisnickomImenuLozinci(tbKorisnickoIme.Text, tbLozinka.Text);

        if (korisnik != null)
        {
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, tbKorisnickoIme.Text, DateTime.Now,
                DateTime.Now.AddMinutes(120), chkZapamtiMe.Checked, "custom data");
            string cookieStr = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieStr);

            if (chkZapamtiMe.Checked)
                cookie.Expires = ticket.Expiration;

            cookie.Path = FormsAuthentication.FormsCookiePath;
            Response.Cookies.Add(cookie);

            Response.Redirect("User/Default.aspx", true);
        }
        else
        {
            phStatusPrijave.Visible = true;
            lblStatusPrijave.Text = "Pogresni korisnicko ime ili lozinka!";
        }
    }
开发者ID:dzenisan,项目名称:bezpanike,代码行数:25,代码来源:Login.aspx.cs

示例2: cmdLogin_ServerClick

    private void cmdLogin_ServerClick(object sender, System.EventArgs e)
    {
        if (ValidateUser(txtUserName.Value, txtUserPass.Value))
            {
                FormsAuthenticationTicket tkt;
                string cookiestr;
                HttpCookie ck;
                tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now, DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
                cookiestr = FormsAuthentication.Encrypt(tkt);
                ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
                if (chkPersistCookie.Checked)
                    ck.Expires = tkt.Expiration;
                ck.Path = FormsAuthentication.FormsCookiePath;
                Response.Cookies.Add(ck);

                string strRedirect;
                strRedirect = Request["ReturnUrl"];
                if (strRedirect == null)
                    strRedirect = "default.aspx";
                Response.Redirect(strRedirect, false);
            }
            else
            {
                Response.Redirect("logon.aspx", false);
            }
    }
开发者ID:tonybaloney,项目名称:No-More-Spreadsheets,代码行数:26,代码来源:Logon.aspx.cs

示例3: OnActionGrid_PageSizeChanged

 protected void OnActionGrid_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)
 {
     HttpCookie actionGridPageSizeCookie = new HttpCookie("cand_actgrdps");
     actionGridPageSizeCookie.Expires.AddDays(30);
     actionGridPageSizeCookie.Value = e.NewPageSize.ToString();
     Response.Cookies.Add(actionGridPageSizeCookie);
 }
开发者ID:netthanhhung,项目名称:Neos,代码行数:7,代码来源:CandidateProfile.aspx.cs

示例4: GetCartFromCookies

 public IList<CartItem> GetCartFromCookies()
 {
     IList<CartItem> CartItems = new List<CartItem>();
     HttpRequest Request = HttpContext.Current.Request;
     HttpResponse Response = HttpContext.Current.Response;
     HttpServerUtility Server = HttpContext.Current.Server;
     string cookieName = "_cart";
     HttpCookie cookie = Request.Cookies[cookieName];
     if (cookie == null)
     {
         cookie = new HttpCookie(cookieName, "[]");
         Response.Cookies.Add(cookie);
         return CartItems;
     }
     string cartJson = Server.UrlDecode(cookie.Value);
     Newtonsoft.Json.Linq.JArray arrya = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(cartJson);
     if (CartItems == null)
     {
         cookie.Value = "[]";
         Response.Cookies.Add(cookie);
         return CartItems;
     }
     CartItems = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<CartItem>>(cartJson);
     return CartItems;
 }
开发者ID:phiree,项目名称:NTSBase2,代码行数:25,代码来源:Cart.cs

示例5: CreateCookie

    private void CreateCookie(string period)
    {
        if (Request.Cookies[cookieName] == null)
        {
            HttpCookie cookie = new HttpCookie("UserAccount");
            cookie["username"] = txtUserName.Text;
            cookie["password"] = txtPassword.Text;
            //cookie["password"] = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5");
            //如果要对保存的密码加密,使用注释的语句

            switch (period)
            {
                case "保存一天":
                    cookie.Expires = DateTime.Now.AddDays(1);
                    break;
                case "保存一月":
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    break;
                case "保存一年":
                    cookie.Expires = DateTime.Now.AddYears(1);
                    break;
                default:
                    break;
            }

            Response.Cookies.Add(cookie);
        }
    }
开发者ID:ningboliuwei,项目名称:Course_ASPNET,代码行数:28,代码来源:Login.aspx.cs

示例6: btnSubmit_Click

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string name = this.txtUserName.Text.Trim();
        string pwd = this.txtPassword.Text.Trim();
        try
        {
            if (name.Length == 0 || pwd.Length == 0)
            {
                MessageBox.Show(this, "user name and password cannot be empty.");
                return;
            }
            if (user.Login(name, pwd))
            {
                Session["User"] = name;
                UserDAL.LoginUserID = name;
                if (this.chkRem.Checked)
                {
                    HttpCookie userid = new HttpCookie("UserName");
                    userid.Value = name;
                    userid.Expires = DateTime.Now.AddDays(7);
                    Response.Cookies.Add(userid);
                }
                else
                {
                    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
                }
                Response.Redirect("Default.aspx", true);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(this, ex.Message);
        }

    }
开发者ID:ChegnduJackli,项目名称:Projects,代码行数:35,代码来源:UserLogin.aspx.cs

示例7: Page_Init

    protected void Page_Init(object sender, EventArgs e)
    {
        // Код ниже защищает от XSRF-атак
        var requestCookie = Request.Cookies[AntiXsrfTokenKey];
        Guid requestCookieGuidValue;
        if (requestCookie != null && Guid.TryParse(requestCookie.Value, out requestCookieGuidValue))
        {
            // Использование маркера Anti-XSRF из cookie
            _antiXsrfTokenValue = requestCookie.Value;
            Page.ViewStateUserKey = _antiXsrfTokenValue;
        }
        else
        {
            // Создание нового маркера Anti-XSRF и его сохранение в cookie
            _antiXsrfTokenValue = Guid.NewGuid().ToString("N");
            Page.ViewStateUserKey = _antiXsrfTokenValue;

            var responseCookie = new HttpCookie(AntiXsrfTokenKey)
            {
                HttpOnly = true,
                Value = _antiXsrfTokenValue
            };
            if (FormsAuthentication.RequireSSL && Request.IsSecureConnection)
            {
                responseCookie.Secure = true;
            }
            Response.Cookies.Set(responseCookie);
        }

        Page.PreLoad += master_Page_PreLoad;
    }
开发者ID:kreeeeg,项目名称:site,代码行数:31,代码来源:Site.master.cs

示例8: AddAgendaItem

 protected void AddAgendaItem(object sender, EventArgs e)
 {
     HttpCookie cookie = Request.Cookies["BrowserDate"];
     if (cookie == null)
     {
         cookie = new HttpCookie("BrowserDate");
         cookie.Value = DateTime.Now.ToString();
         cookie.Expires = DateTime.Now.AddDays(22);
         Response.Cookies.Add(cookie);
     }
     Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));
     AgendaItemTextBox.Text = dat.stripHTML(AgendaItemTextBox.Text.Trim());
     AgendaDescriptionTextBox.Text = dat.stripHTML(AgendaDescriptionTextBox.Text.Trim());
     if (AgendaItemTextBox.Text.Trim() != "")
     {
         AgendaLiteral.Text += "<div style=\"padding: 0px; padding-bottom: 3px;\" class=\"AddLink\">" +
             dat.BreakUpString(AgendaItemTextBox.Text.Trim(), 44) + "</div>";
         if (AgendaDescriptionTextBox.Text.Trim() != "")
         {
             AgendaLiteral.Text += "<div style=\"padding: 0px; padding-left: 20px; padding-bottom: 3px; color: #cccccc; font-family: arial; font-size: 11px;\">" +
             dat.BreakUpString(AgendaDescriptionTextBox.Text.Trim(), 44) + "</div>";
         }
     }
     else
     {
         AgendaErrorLabel.Text = "Must include the item title.";
     }
 }
开发者ID:aleksczajka,项目名称:Hippo-Code---OLD,代码行数:28,代码来源:EnterGroupEvent.aspx.cs

示例9: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));
        if (Session["User"] == null)
        {
            Response.Redirect("~/Home.aspx");

        }

        if (Request.QueryString["ID"] == null)
            Response.Redirect("Home.aspx");

        if (dat.HasEventPassed(Request.QueryString["ID"].ToString()))
        {
            DataView dvName = dat.GetDataDV("SELECT * FROM Events WHERE ID="+
                Request.QueryString["ID"].ToString());
            Response.Redirect(dat.MakeNiceName(dvName[0]["Header"].ToString()) + "_" +
                Request.QueryString["ID"].ToString() + "_Event");
        }
    }
开发者ID:aleksczajka,项目名称:Hippo-Code---OLD,代码行数:28,代码来源:EditEvent.aspx.cs

示例10: btnCookie_Click

 protected void btnCookie_Click(object sender, EventArgs e)
 {
     //luodaan keksi ja kirjoitetaan siihen viesti
     HttpCookie cookie = new HttpCookie("Message", txtMessage.Text);
     cookie.Expires = DateTime.Now.AddMinutes(15);
     Response.Cookies.Add(cookie);
 }
开发者ID:EsaSalmik,项目名称:IIO13200-ASPNET-OHJELMOINTI,代码行数:7,代码来源:SourceEvening.aspx.cs

示例11: btn_auth_Click

    /// <summary>
    /// Click event for authorize button. Validates the user's credentials against the locked trip
    /// and sets cookies for session authentication.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_auth_Click(object sender, EventArgs e)
    {
        Trip trip = GetTrip(Request["id"]);
        if (trip == null) { return; }

        string password = TripAuthPassword.Text;

        //Clear input box
        TripAuthPassword.Text = "";

        if (String.IsNullOrWhiteSpace(password)) { return; }

        string hash = Trip.GetSHA1Hash(password);

        if (hash == trip.Password)
        {
            string token = Trip.GetMD5Hash(Session.SessionID);
            HttpCookie cookie = new HttpCookie("authtoken", token);
            Response.Cookies.Add(cookie);
            Session[token] = trip.ID;
            //Response.Cookies["authsession"][hash] = trip.ID;
            //Response.Cookies["authsession"].Expires = DateTime.Now.AddHours(1);
            //Redirect to prevent accidental resubmission
            Response.Redirect(Request.Url.ToString(), false);
        }
    }
开发者ID:azach,项目名称:JumpPad,代码行数:32,代码来源:ViewTrip.aspx.cs

示例12: validateUserEmail

    protected void validateUserEmail(object sender, LoginCancelEventArgs e)
    {
        TextBox EmailAddressTB =
            ((TextBox)PWRecovery.UserNameTemplateContainer.FindControl("EmailAddressTB"));

        Literal ErrorLiteral =
          ((Literal)PWRecovery.UserNameTemplateContainer.FindControl("ErrorLiteral"));

        MembershipUser mu = Membership.GetUser(PWRecovery.UserName);

        if (mu != null) // The username exists
        {
            if (mu.Email.Equals(EmailAddressTB.Text)) // Their email matches
            {
                //ProfileCommon newProfile = Profile.GetProfile(PWRecovery.UserName);
                HttpCookie appCookie = new HttpCookie("usernameCookie");
                //appCookie.Value = newProfile.FullName;
                appCookie.Expires = DateTime.Now.AddMinutes(3);
                Response.Cookies.Add(appCookie);
                ErrorLiteral.Text = "An email has been sent to your email account with a new password.";
            }
            else
            {
                e.Cancel = true;
                ErrorLiteral.Text = "Your username and password do not match";
            }
        }
        else
        {
            e.Cancel = true;
            ErrorLiteral.Text = "No such user found.";
        }
    }
开发者ID:WilliamClydeMoon,项目名称:Humat,代码行数:33,代码来源:PasswordReset.aspx.cs

示例13: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlMeta hm = new HtmlMeta();
        HtmlHead head = (HtmlHead)Page.Header;
        hm.Name = "ROBOTS";
        hm.Content = "NOINDEX, FOLLOW";
        head.Controls.AddAt(0, hm);

        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

        DataView dvGroup = dat.GetDataDV("SELECT * FROM Groups WHERE ID="+Request.QueryString["ID"].ToString());
        if (dvGroup[0]["Host"].ToString() == Session["User"].ToString())
        {
            TheLabel.Text = "Since you are the primary host of the group, you must first designate another host for the group. Go to your group's home page and click on 'Edit Members' Prefs'.";
            Button3.Visible = false;
        }
    }
开发者ID:aleksczajka,项目名称:Hippo-Code---OLD,代码行数:25,代码来源:RevokeMembership.aspx.cs

示例14: Page_Load

 /*
  * Setup session variables & check for authentication
  */
 protected void Page_Load(object sender, EventArgs evt)
 {
     if (!Page.IsPostBack) {
         string server = Request.QueryString["server"];
         if (server != null) {
             server = HttpUtility.UrlDecode(server);
             Session["FieldScope_MetaLens_Server"] = server;
         } else {
             server = (string)Session["FieldScope_MetaLens_Server"];
         }
         string lat = Request.QueryString["lat"];
         if (lat != null) {
             lat = HttpUtility.UrlDecode(lat);
             Session["FieldScope_MetaLens_Latitude"] = lat;
         } else {
             lat = (string)Session["FieldScope_MetaLens_Latitude"];
         }
         string lon = Request.QueryString["lon"];
         if (lon != null) {
             lon = HttpUtility.UrlDecode(lon);
             Session["FieldScope_MetaLens_Longitude"] = lon;
         } else {
             lon = (string)Session["FieldScope_MetaLens_Longitude"];
         }
         if ((!Request.Cookies.AllKeys.Contains("MetaLens_Cookie")) ||
             (MetaLens.Service.CheckLogin(server, Request.Cookies["MetaLens_Cookie"].Value) == null)) {
             HttpCookie cookie = new HttpCookie("MetaLens_Cookie", MetaLens.Service.Login(server, USERNAME, PASSWORD));
             cookie.Expires = DateTime.Now.AddMinutes(60);
             Response.SetCookie(cookie);
         }
     }
 }
开发者ID:NGFieldScope,项目名称:JS-FieldScope,代码行数:35,代码来源:MetaLensUpload.aspx.cs

示例15: logueo_Click

 protected void logueo_Click(object sender, EventArgs e)
 {
     HttpCookie page = new HttpCookie("carrito");
     page.Values["value"] = "Carrito.aspx";
     Response.Cookies.Add(page);
     Response.Redirect("Login.aspx");
 }
开发者ID:hexadron,项目名称:lp3,代码行数:7,代码来源:Carrito.aspx.cs


注:本文中的HttpCookie类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。