本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}