本文整理汇总了C#中System.Web.HttpCookieCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# HttpCookieCollection.Remove方法的具体用法?C# HttpCookieCollection.Remove怎么用?C# HttpCookieCollection.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpCookieCollection
的用法示例。
在下文中一共展示了HttpCookieCollection.Remove方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Set
private void Set(HttpCookieCollection cookieCollection, HttpCookie cookie)
{
if (cookieCollection.AllKeys.Contains(cookie.Name))
{
cookieCollection.Remove(cookie.Name);
}
cookieCollection.Add(cookie);
}
示例2: TestCollection
public void TestCollection ()
{
HttpCookieCollection col = new HttpCookieCollection ();
HttpCookie cookie = new HttpCookie ("cookie", "value");
col.Add (cookie);
Assert.AreEqual ("cookie", col["cookie"].Name, "Name is the key");
col.Remove (cookie.Name);
Assert.IsNull (col["cookie"], "removal using name");
}
示例3: 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 ();
}
示例4: RemoveAuthCookies
/// <summary>
/// Removes the authentication cookies.
/// </summary>
/// <param name="cookieCollection">The cookie collection.</param>
private static void RemoveAuthCookies(HttpCookieCollection cookieCollection) {
// borrar cualquier cookie con el mismo nombre de la cookie de autenticación
if (!cookieCollection.AllKeys.Contains(FormsAuthentication.FormsCookieName)) return;
//
// obtener nombre definido paral a cookie
var cookieName = FormsAuthentication.FormsCookieName;
//
// recuperar el valor de la cookie antes de eliminarla
var httpCookie = cookieCollection.Get(cookieName);
//
// la cookie existe?
if (httpCookie == null) return;
//
// eliminar la cookie
cookieCollection.Remove(cookieName);
//
// determinar número de cookies en que se guardó el boleto de autenticación
int numberOfCookies;
if (!int.TryParse(httpCookie.Value, out numberOfCookies)) return;
for (var i = 1; i < numberOfCookies; i++) cookieCollection.Remove((cookieName + i));
}
示例5: SetSessionCookiesForPortal
internal void SetSessionCookiesForPortal (HttpCookieCollection cookies)
{
if (cookies == null || cookies.Count == 0)
return;
if (!(context.WorkerRequest is IHttpExtendedWorkerRequest))
return;
IHttpExtendedWorkerRequest exWorker = (IHttpExtendedWorkerRequest) context.WorkerRequest;
bool inPortletMode = !context.IsServletRequest;
bool shouldStoreCookiesCollection = false;
HttpSession javaSession = exWorker.GetSession (false);
if (javaSession == null && inPortletMode)
javaSession = exWorker.GetSession (true);
if (javaSession == null)
return;
object sessionLock = GetJavaSessionLock (javaSession);
lock (sessionLock) {
Hashtable sessionCookies = (Hashtable)javaSession.getAttribute (SessionCookies);
if (sessionCookies == null)
if (inPortletMode) {
sessionCookies = new Hashtable ();
shouldStoreCookiesCollection = true;
}
else
return;
ArrayList sessionStoredCookies = null;
for (int i=0; i < cookies.Count; i++) {
HttpCookie cookie = cookies[i];
if (sessionCookies [cookie.Name] != null || inPortletMode) {
sessionCookies [cookie.Name] = cookie;
if (sessionStoredCookies == null)
sessionStoredCookies = new ArrayList();
sessionStoredCookies. Add (cookie.Name);
}
}
if (sessionStoredCookies != null)
foreach (object key in sessionStoredCookies)
cookies.Remove ((string) key);
if (shouldStoreCookiesCollection)
javaSession.setAttribute (SessionCookies, sessionCookies);
}
}
示例6: 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);
}
}
示例7: ClearSwitches
protected void ClearSwitches(HttpCookieCollection cookies)
{
foreach (var key in cookies.AllKeys)
{
if (Regex.IsMatch(key, @"^itofs_"))
{
cookies.Remove(key);
}
}
}
示例8: updateCookie
private static void updateCookie(HttpCookie cookie, HttpCookieCollection cookies)
{
cookies.Remove(cookie.Name);
cookies.Add(cookie);
}