• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# HttpCookie类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: btnLogin_Click

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bool IsAuthenticated = false;
        try
        {
            IsAuthenticated = Account.AuthenticateUser(txtUserName.Text, txtEmail.Text, txtPassword.Text);
            if (IsAuthenticated)
            {
                //set cookie with login time
                HttpCookie loginCookie = new HttpCookie("loginCookie");
                loginCookie.Value = DateTime.Now.ToString();
                Response.Cookies.Add(loginCookie);
                Response.Redirect("Default.aspx");

            }
            else
            {
                lblError.Text = "Sorry, your credentials were not recognized. Access denied! :( ";
                lblError.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message.ToString();
            lblError.Visible = true;
        }
    }
开发者ID:tqheel,项目名称:hi-teq-pub,代码行数:27,代码来源:Login.aspx.cs


示例17: RemoveMember

    protected void RemoveMember(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", ":")));

        dat.Execute("DELETE FROM User_Friends WHERE UserID=" + Session["User"].ToString() +
            " AND FriendID =" + Request.QueryString["ID"].ToString());

        dat.Execute("DELETE FROM User_Friends WHERE UserID=" + Request.QueryString["ID"].ToString() +
            " AND FriendID =" + Session["User"].ToString());

        dat.Execute("DELETE FROM UserFriendPrefs WHERE UserID=" + Session["User"].ToString() +
            " AND FriendID =" + Request.QueryString["ID"].ToString());

        dat.Execute("DELETE FROM UserFriendPrefs WHERE UserID=" + Request.QueryString["ID"].ToString() +
            " AND FriendID =" + Session["User"].ToString());

        RemovePanel.Visible = false;
        ThankYouPanel.Visible = true;
    }
开发者ID:aleksczajka,项目名称:Hippo-Code---OLD,代码行数:27,代码来源:RemoveFriend.aspx.cs


示例18: DDLJezik_SelectedIndexChanged

 protected void DDLJezik_SelectedIndexChanged(object sender, EventArgs e)
 {
     HttpCookie cookie = new HttpCookie("Postavke");
     cookie.Values["jezik"] = DDLJezik.SelectedValue;
     cookie.Expires.AddMonths(1);
     Response.Cookies.Add(cookie);
 }
开发者ID:vsite-prog,项目名称:PIN,代码行数:7,代码来源:Default.aspx.cs


示例19: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     switch (Request.QueryString["Mode"])
     {
         case "Location":
             {
                 HttpCookie _locationCookies = new HttpCookie("Location");
                 _locationCookies["LocationId"] = Request.QueryString["LocationId"];
                 _locationCookies["LocationName"] = Request.QueryString["LocationName"];
                 _locationCookies.Expires = DateTime.Now.AddYears(1);
                 Response.Cookies.Add(_locationCookies);
                 break;
             }
         case "Language":
             {
                 HttpCookie _LanguageCookies = new HttpCookie("Language");
                 _LanguageCookies["LanguageId"] = Request.QueryString["LanguageId"];
                 _LanguageCookies["LanguageName"] = Request.QueryString["LanguageName"];
                 _LanguageCookies.Expires = DateTime.Now.AddYears(1);
                 Response.Cookies.Add(_LanguageCookies);
                 break;
             }
     }
     Response.Redirect(Request.UrlReferrer.ToString());
 }
开发者ID:farhad85,项目名称:Salestan,代码行数:25,代码来源:ChangeLocation.aspx.cs


示例20: RegisterForCourses_Click

    protected void RegisterForCourses_Click(object sender, EventArgs e)
    {
        HttpCookie ConferencesCoursesRegistering = new HttpCookie("CoursesToRegisterFor");
        ConferencesCoursesRegistering.Expires = DateTime.Now.AddMinutes(20);
        ConferencesCoursesRegistering.Path = "/";
        Dictionary<string, Dictionary<string, float>> coursesToRegisterFor = new Dictionary<string, Dictionary<string, float>>();
        List<Conference> chosenConferences = new List<Conference>();

        int coursesChecked = 0;
        foreach (GridViewRow row in coursesForAllConferences.Rows)
        {
            Conference newConference = new Conference(row.Cells[0].Text);
            CheckBox registerForCourse = ((CheckBox)row.Cells[7].FindControl("RegisterForEventCB"));
            if (registerForCourse.Checked)
            {
                coursesChecked += 1;
                ConferencesCoursesRegistering.Values.Add(row.Cells[1].Text, row.Cells[0].Text);
            }
        }

        if (coursesChecked > 0)
        {
            Response.Cookies.Add(ConferencesCoursesRegistering);

            Response.Redirect("FinalizeRegistration.aspx");
        }
        else
        {
            OneEventChosen.IsValid = false;
        }
    }
开发者ID:movies28423,项目名称:Conference-Register,代码行数:31,代码来源:RegisterForConferences.aspx.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# HttpError类代码示例发布时间:2022-05-24
下一篇:
C# HttpControllerDescriptor类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap