本文整理汇总了C#中System.Web.HttpCookieCollection.Set方法的典型用法代码示例。如果您正苦于以下问题:C# HttpCookieCollection.Set方法的具体用法?C# HttpCookieCollection.Set怎么用?C# HttpCookieCollection.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpCookieCollection
的用法示例。
在下文中一共展示了HttpCookieCollection.Set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAuthorizationCookie
public static string GetAuthorizationCookie(HttpCookieCollection cookies, string code, IBaseDb db)
{
//var code = request.QueryString["code"];
var stream = HttpTools.PostStream("https://oauth.yandex.ru/token",
string.Format("grant_type=authorization_code&code={0}&client_id={1}&client_secret={2}", code, ClientId, Password));
var model = SerializeTools.Deserialize<TokenModel>(stream);
var userCookie = new HttpCookie("yandex_token")
{
Value = model.access_token,
Expires = DateTime.Now.AddDays(30)
};
stream = HttpTools.PostStream(InfoUrl, string.Format("oauth_token={0}", userCookie.Value));
var email = SerializeTools.Deserialize<UserModel>(stream).default_email;
var user = db.SingleOrDefault<User>(u => u.Email == email);
cookies.Set(userCookie);
var rolesCookie = new HttpCookie("roles") {Value = string.Join(",", user.UserRoles.Select(r => r.Code)), Expires = DateTime.Now.AddDays(30)};
cookies.Set(rolesCookie);
return model.access_token;
}
示例2: WriteInternal
internal override void WriteInternal(byte[] value, string name, string path, string domain, DateTime expirationTime, bool secure, bool httpOnly, HttpCookieCollection requestCookies, HttpCookieCollection responseCookies)
{
string cookieValue = Convert.ToBase64String(value);
this.DeleteInternal(name, path, domain, requestCookies, responseCookies);
foreach (KeyValuePair<string, string> current in this.GetCookieChunks(name, cookieValue))
{
HttpCookie httpCookie = new HttpCookie(current.Key, current.Value);
httpCookie.Secure = true;
httpCookie.HttpOnly = httpOnly;
httpCookie.Path = path;
if (!string.IsNullOrEmpty(domain))
{
httpCookie.Domain = domain;
}
if (expirationTime != DateTime.MinValue)
{
httpCookie.Expires = expirationTime;
}
responseCookies.Set(httpCookie);
//if (DiagnosticUtility.ShouldTrace(TraceEventType.Information))
//{
// TraceEventType arg_A6_0 = TraceEventType.Information;
// int arg_A6_1 = 786438;
// string arg_A6_2 = null;
// ChunkedCookieHandlerTraceRecord.Action arg_A0_0 = ChunkedCookieHandlerTraceRecord.Action.Writing;
// HttpCookie expr_9A = httpCookie;
// TraceUtility.TraceEvent(arg_A6_0, arg_A6_1, arg_A6_2, new ChunkedCookieHandlerTraceRecord(arg_A0_0, expr_9A, expr_9A.Path), null);
//}
}
}
示例3: DuplicateNames
public void DuplicateNames ()
{
HttpCookieCollection col = new HttpCookieCollection ();
HttpCookie cookie1 = new HttpCookie ("cookie", "value1");
HttpCookie cookie2 = new HttpCookie ("cookie", "value2");
col.Add (cookie1);
col.Add (cookie2);
Assert.AreEqual ("value1", col["cookie"].Value, "add should use first used cookie");
col.Set (cookie2);
Assert.AreEqual ("value2", col["cookie"].Value, "set should use last used cookie");
col.Clear ();
col.Add (cookie1);
col.Add (cookie2);
// Bug #553150
HttpCookie tmp = col.Get (0);
Assert.AreEqual ("cookie", tmp.Name, "#A1");
Assert.AreEqual ("value1", tmp.Value, "#A1-1");
tmp = col.Get (1);
Assert.AreEqual ("cookie", tmp.Name, "#A2");
Assert.AreEqual ("value2", tmp.Value, "#A2-1");
}
示例4: ForgetLoggedInUser
public static void ForgetLoggedInUser(HttpCookieCollection requestCookies, HttpCookieCollection responseCookies)
{
DeleteRememberedSession(requestCookies);
var cookie = responseCookies.Get(CookieName);
cookie.Path = HttpContext.Current.Request.ApplicationPath;
cookie.Expires = DateTime.Now;
cookie.Value = "";
responseCookies.Set(cookie);
}
示例5: Set
private void Set(HttpCookieCollection cookies, string content)
{
// Could set MaxAge, to allow persistent cookies
var cookie = new HttpCookie(_cookieName, content)
{
HttpOnly = true
};
cookies.Set(cookie);
}
示例6: Deny_Unrestricted
public void Deny_Unrestricted ()
{
HttpCookieCollection jar = new HttpCookieCollection ();
jar.Add (biscuit);
jar.CopyTo (new object[1], 0);
Assert.IsNull (jar.GetKey (0), "GetKey");
jar.Remove ("chocolat");
jar.Set (biscuit);
Assert.IsNotNull (jar.Get (0), "Get(int)");
Assert.IsNull (jar.Get ("chocolat"), "Get(string)");
Assert.IsNotNull (jar[0], "this[int]");
Assert.IsNull (jar["chocolat"], "this[string]");
Assert.AreEqual (1, jar.AllKeys.Length, "AllKeys");
jar.Clear ();
}
示例7: DeleteInternal
internal void DeleteInternal(string name, string path, string domain, HttpCookieCollection requestCookies, HttpCookieCollection responseCookies)
{
foreach (HttpCookie current in this.GetCookieChunks(name, requestCookies))
{
HttpCookie httpCookie = new HttpCookie(current.Name, null);
httpCookie.Path = path;
httpCookie.Expires = DateTime.UtcNow.AddDays(-1.0);
if (!string.IsNullOrEmpty(domain))
{
httpCookie.Domain = domain;
}
//if (DiagnosticUtility.ShouldTrace(TraceEventType.Information))
//{
// TraceUtility.TraceEvent(TraceEventType.Information, 786438, null, new ChunkedCookieHandlerTraceRecord(ChunkedCookieHandlerTraceRecord.Action.Deleting, current, path), null);
//}
responseCookies.Set(httpCookie);
}
}
示例8: GetAuthorizationContext
public static AuthorizationContext GetAuthorizationContext(string cookieValue, string formValue)
{
HttpCookieCollection requestCookies = new HttpCookieCollection();
NameValueCollection formCollection = new NameValueCollection();
Mock<AuthorizationContext> mockAuthContext = new Mock<AuthorizationContext>();
mockAuthContext.Expect(c => c.HttpContext.Request.ApplicationPath).Returns("/SomeAppPath");
mockAuthContext.Expect(c => c.HttpContext.Request.Cookies).Returns(requestCookies);
mockAuthContext.Expect(c => c.HttpContext.Request.Form).Returns(formCollection);
if (!String.IsNullOrEmpty(cookieValue)) {
requestCookies.Set(new HttpCookie(_antiForgeryTokenCookieName, cookieValue));
}
if (!String.IsNullOrEmpty(formValue)) {
formCollection.Set(AntiForgeryData.GetAntiForgeryTokenName(null), formValue);
}
return mockAuthContext.Object;
}
示例9: SetNewCsrfCookie
public static HttpCookie SetNewCsrfCookie(HttpCookieCollection cookies, string VKeCRMToken)
{
HttpCookie cookie = new HttpCookie(TokenName)
{
Value = VKeCRMToken,
Domain = "localhost",
Secure = true,
};
if (cookies[TokenName] == null)
{
cookies.Add(cookie);
}
else
{
cookies.Set(cookie);
}
//save token in session
HttpContext.Current.Session[TokenName] = VKeCRMToken;
return cookie;
}
示例10: Update
public static void Update(HttpCookieCollection cookies, SerializableCookie[] serializableCookies)
{
cookies.Clear();
foreach (var cookie in serializableCookies)
cookies.Set(cookie);
}
示例11: GetSessionCookiesForPortal
internal void GetSessionCookiesForPortal (HttpCookieCollection cookies)
{
if (context == null)
return;
if (!(context.WorkerRequest is IHttpExtendedWorkerRequest))
return;
IHttpExtendedWorkerRequest exWorker = (IHttpExtendedWorkerRequest) context.WorkerRequest;
HttpSession javaSession = exWorker.GetSession (false);
if (javaSession == null)
return;
object sessionLock = GetJavaSessionLock (javaSession);
lock (sessionLock) {
Hashtable sessionCookies = (Hashtable) javaSession.getAttribute (SessionCookies);
if (sessionCookies == null)
return;
ArrayList expiredCookies = null;
foreach (string key in sessionCookies.Keys) {
HttpCookie sessionCookie = (HttpCookie) sessionCookies [key];
if (sessionCookie.Expires.Ticks != 0 &&
sessionCookie.Expires.Ticks < DateTime.Now.Ticks) {
if (cookies [key] != null)
cookies.Remove (key);
else {
if (expiredCookies == null)
expiredCookies = new ArrayList();
expiredCookies.Add (key);
}
}
else
cookies.Set (sessionCookie);
}
if (expiredCookies != null)
foreach (object key in expiredCookies)
sessionCookies.Remove (key);
}
}