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


C# Cookie.ToCookieString方法代码示例

本文整理汇总了C#中System.Net.Cookie.ToCookieString方法的典型用法代码示例。如果您正苦于以下问题:C# Cookie.ToCookieString方法的具体用法?C# Cookie.ToCookieString怎么用?C# Cookie.ToCookieString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Cookie的用法示例。


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

示例1: LoginRequest

        /// <summary>
        /// Tries to log a user in.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="search">The search part of the location where to redirect to on success.</param>
        /// <returns></returns>
        public Response LoginRequest(string username, string password, string search)
        {
            int userID = Proxy.SessionManager.UserID(username);
            if (userID == -1)
            {
                return PageWithErrorMessage("login.html", "wrong_username", "Username does not exist.", username);
            }
            else if (!Proxy.SessionManager.IsCorrectPW(username, password))
            {
                return PageWithErrorMessage("login.html", "wrong_password", "Password is incorrect.", username);
            }

            // User+PW correct
            Logger.Metric(userID, "Login.");
            Proxy.SessionManager.LogUserIn(ClientIP, userID);

            // Set cookies.
            Cookie idCookie = new Cookie("uid", "" + userID, "/");
            Cookie nameCookie = new Cookie("uname", username, "/");
            DateTime expiryDate = Proxy.SessionManager.GetSessionExpiryDate(userID);
            idCookie.Expires = expiryDate;
            nameCookie.Expires = expiryDate;

            // We must use Headers.Add (Not AddHeader, not SetCookie and not AppendCookie)
            // as in the other cases only a comma separated list in one Set-Cookie would be created,
            // which browsers do not understand. C# sucks.
            _clientHttpContext.Response.Headers.Add("Set-Cookie", idCookie.ToCookieString());
            _clientHttpContext.Response.Headers.Add("Set-Cookie", nameCookie.ToCookieString());

            // Redirect to the User Homepage.
            _clientHttpContext.Response.Redirect("/trotro-user.html" + search);
            return new Response();
        }
开发者ID:o0111,项目名称:ruralcafe,代码行数:40,代码来源:LocalInternalRequestHandler.cs

示例2: SendLogoutCookies

        /// <summary>
        /// Sends expired cookies, so they will be deleted at the client side.
        /// </summary>
        private void SendLogoutCookies()
        {
            // Set cookies.
            Cookie idCookie = new Cookie("uid", "", "/");
            Cookie nameCookie = new Cookie("uname", "", "/");
            Cookie statusCookie = new Cookie("status", "", "/");
            // Expiry date in the past.
            DateTime expiryDate = DateTime.Now.AddDays(-1);
            idCookie.Expires = expiryDate;
            nameCookie.Expires = expiryDate;
            statusCookie.Expires = expiryDate;

            _clientHttpContext.Response.Headers.Add("Set-Cookie", idCookie.ToCookieString());
            _clientHttpContext.Response.Headers.Add("Set-Cookie", nameCookie.ToCookieString());
            _clientHttpContext.Response.Headers.Add("Set-Cookie", statusCookie.ToCookieString());
        }
开发者ID:o0111,项目名称:ruralcafe,代码行数:19,代码来源:LocalInternalRequestHandler.cs


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