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