當前位置: 首頁>>代碼示例>>C#>>正文


C# Response.WithCookie方法代碼示例

本文整理匯總了C#中Nancy.Response.WithCookie方法的典型用法代碼示例。如果您正苦於以下問題:C# Response.WithCookie方法的具體用法?C# Response.WithCookie怎麽用?C# Response.WithCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nancy.Response的用法示例。


在下文中一共展示了Response.WithCookie方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AuthModule

        public AuthModule()
            : base("/api")
        {
            Post["/authenticate"] = x => {
                var bind = this.Bind<LoginRequest>();

                UserManager<User> manager = new UserManager<User>(new UserStore());

                var user = manager.Find(bind.Username, bind.Password);

                if (user == null)
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.Unauthorized
                    };
                }
                else
                {
                    var response = new Response
                    {
                        StatusCode = HttpStatusCode.OK
                    };
                    return response.WithCookie("sq-valid", user.UserName, DateTime.Now.AddMinutes(5));
                }
            };

            Get["/logout"] = x => {
                var response = new Response
                {
                    StatusCode = HttpStatusCode.OK
                };
                return response.WithCookie("sq-valid", null, DateTime.Now.AddYears(-5));
            };
        }
開發者ID:fugaku,項目名稱:StockQuote,代碼行數:35,代碼來源:AuthModule.cs

示例2: Save

        public void Save(ISession session, Response response)
        {
            if (session == null || !session.HasChanged)
            {
                return;
            }

            string sessionID = null;

            if (!response.Cookies.Any(cookie => cookie.Name == cookieName))
            {
                sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(DateTime.UtcNow.ToLongTimeString()));
                response.WithCookie(new NancyCookie(cookieName, sessionID));
            }
            else
            {
                sessionID = response.Cookies.Where(cookie => cookie.Name == cookieName).Select(cookie => cookie.Value).First();
            }

            store[sessionID] = session.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
        }
開發者ID:CollapsedTotoProductionCommittee,項目名稱:CollapsedToto,代碼行數:21,代碼來源:MemorySession.cs


注:本文中的Nancy.Response.WithCookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。