当前位置: 首页>>代码示例>>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;未经允许,请勿转载。