本文整理汇总了C#中System.Web.HttpResponseBase.AppendCookie方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.AppendCookie方法的具体用法?C# HttpResponseBase.AppendCookie怎么用?C# HttpResponseBase.AppendCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.AppendCookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCookie
public static void AddCookie(HttpResponseBase Response, string name, string value, int day, int hours, int minutes, int seconds)
{
HttpCookie cookie = new HttpCookie(name);
TimeSpan ts = new TimeSpan(day, hours, minutes, seconds);
cookie.Expires = DateTime.Now.Add(ts);
cookie.Value = value;
Response.AppendCookie(cookie);
}
示例2: PrepareResponse
private void PrepareResponse(HttpResponseBase response, string downloadTokenValue, string zipFilename)
{
response.ContentType = "application/zip";
if (string.IsNullOrEmpty(downloadTokenValue) == false)
{
//downloadTokenValue will have been provided in the form submit via the hidden input field
response.AppendCookie(new HttpCookie("fileDownloadToken", downloadTokenValue));
}
response.AddHeader("content-disposition",
string.Format("attachment; filename={0}.zip", zipFilename));
}
示例3: ValidateUser
/// <summary>
/// Authenticates a user via the MembershipProvider and creates the associated forms authentication ticket.
/// </summary>
/// <param name="logon">Logon</param>
/// <param name="response">HttpResponseBase</param>
/// <returns>bool</returns>
public static bool ValidateUser(Logon logon, HttpResponseBase response)
{
bool result = false;
if (Membership.ValidateUser(logon.Username, logon.Password))
{
// Create the authentication ticket with custom user data.
var serializer = new JavaScriptSerializer();
string userData = serializer.Serialize(UserManager.User);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
logon.Username,
DateTime.Now,
DateTime.Now.AddDays(30),
true,
userData,
FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
//encTicket = ZipLib.Zip(encTicket);
// Create the cookie.
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName);
cookie.Expires = DateTime.Now.AddDays(1);
cookie.Value = encTicket;
response.AppendCookie(cookie);
//response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
result = true;
}
return result;
}