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


C# Response.AddCookie方法代码示例

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


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

示例1: Should_output_the_responses_cookies

        public void Should_output_the_responses_cookies()
        {
            var cookie1 = A.Fake<INancyCookie>();
            var cookie2 = A.Fake<INancyCookie>();
            var r = new Response();
            r.AddCookie(cookie1).AddCookie(cookie2);

            A.CallTo(() => cookie1.ToString()).Returns("the first cookie");
            A.CallTo(() => cookie2.ToString()).Returns("the second cookie");

            SetupRequestProcess(r);

            handler.ProcessRequest(context);
            A.CallTo(() => this.response.AddHeader("Set-Cookie", "the first cookie")).MustHaveHappened();
            A.CallTo(() => this.response.AddHeader("Set-Cookie", "the second cookie")).MustHaveHappened();
        }
开发者ID:ryansroberts,项目名称:Nancy,代码行数:16,代码来源:HancyHandlerFixture.cs

示例2: Should_output_the_responses_cookies

        public void Should_output_the_responses_cookies()
        {
            // Given
            var cookie1 = A.Fake<INancyCookie>();
            var cookie2 = A.Fake<INancyCookie>();
            var r = new Response();
            r.AddCookie(cookie1).AddCookie(cookie2);
            var nancyContext = new NancyContext { Response = r };

            A.CallTo(() => cookie1.ToString()).Returns("the first cookie");
            A.CallTo(() => cookie2.ToString()).Returns("the second cookie");

            SetupRequestProcess(nancyContext);

            // When
            var task = this.handler.ProcessRequest(context, ar => { }, new object());
            NancyHandler.EndProcessRequest(task);

            // Then
            A.CallTo(() => this.response.AddHeader("Set-Cookie", "the first cookie")).MustHaveHappened();
            A.CallTo(() => this.response.AddHeader("Set-Cookie", "the second cookie")).MustHaveHappened();
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:22,代码来源:NancyHandlerFixture.cs

示例3: Should_set_cookie_with_valid_header

        public void Should_set_cookie_with_valid_header()
        {
            var fakeResponse = new Response() { StatusCode = HttpStatusCode.OK };
            fakeResponse.AddCookie("test", "testvalue");
            var fakeContext = new NancyContext() { Response = fakeResponse };

            this.SetupFakeNancyCompleteCallback(fakeContext);
            var respHeaders = new Dictionary<string, string>();
            ResponseCallBack callback = (status, headers, bodyDelegate) =>respHeaders=(Dictionary<string,string>)headers;

            this.host.ProcessRequest(environment, callback, fakeErrorCallback);
            respHeaders.ContainsKey("Set-Cookie").ShouldBeTrue();
            (respHeaders["Set-Cookie"]=="test=testvalue; path=/").ShouldBeTrue();
        }
开发者ID:ChrisMH,项目名称:Nancy,代码行数:14,代码来源:NancyOwinHostFixture.cs

示例4: Save

        /// <summary>
        /// Save the session into the response
        /// </summary>
        /// <param name="session">Session to save</param>
        /// <param name="response">Response to save into</param>
        public void Save(ISession session, Response response)
        {
            if (session == null || !session.HasChanged)
            {
                return;
            }

            var sb = new StringBuilder();
            foreach (var kvp in session)
            {
                sb.Append(HttpUtility.UrlEncode(kvp.Key));
                sb.Append("=");

                var objectString = this.serializer.Serialize(kvp.Value);

                sb.Append(HttpUtility.UrlEncode(objectString));
                sb.Append(";");
            }

            // TODO - configurable path?
            var encryptedData = this.encryptionProvider.Encrypt(sb.ToString());
            var hmacBytes = this.hmacProvider.GenerateHmac(encryptedData);
            var cookieData = String.Format("{0}{1}", Convert.ToBase64String(hmacBytes), encryptedData);

            var cookie = new NancyCookie(cookieName, cookieData, true);
            response.AddCookie(cookie);
        }
开发者ID:rspacjer,项目名称:Nancy,代码行数:32,代码来源:CookieBasedSessions.cs

示例5: Save

        /// <summary>
        /// Save the session into the response
        /// </summary>
        /// <param name="session">Session to save</param>
        /// <param name="response">Response to save into</param>
        public void Save(ISession session, Response response)
        {
            if (session == null || !session.HasChanged)
            {
                return;
            }

            var sb = new StringBuilder();
            foreach (var kvp in session)
            {
                sb.Append(HttpUtility.UrlEncode(kvp.Key));
                sb.Append("=");

                var objectString = this.formatter.Serialize(kvp.Value);

                sb.Append(HttpUtility.UrlEncode(objectString));
                sb.Append(";");
            }

            // TODO - configurable path?
            var cookie = new NancyCookie(cookieName, this.encryptionProvider.Encrypt(sb.ToString(), this.passPhrase, this.salt), true);
            response.AddCookie(cookie);
        }
开发者ID:ToJans,项目名称:Nancy,代码行数:28,代码来源:CookieBasedSessions.cs


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