本文整理汇总了C#中System.Web.HttpCookieCollection.Get方法的典型用法代码示例。如果您正苦于以下问题:C# HttpCookieCollection.Get方法的具体用法?C# HttpCookieCollection.Get怎么用?C# HttpCookieCollection.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpCookieCollection
的用法示例。
在下文中一共展示了HttpCookieCollection.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
示例2: 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 ();
}
示例3: Add
/// <summary>
/// Converts an HttpCookieCollection into parameters
/// </summary>
/// <param name="cookies">An HttpCookieCollection</param>
public void Add(HttpCookieCollection cookies)
{
var count = cookies.Count;
for(var index = 0; index < count; index++)
{
var cookie = cookies.Get(index);
Add(cookie.Name, cookie.Value);
}
}
示例4: Add
internal void Add ( HttpCookieCollection c )
{
int count = c.Count;
for ( int i = 0 ; i < count ; i++ )
{
HttpCookie cookie = c.Get ( i );
base.Add ( cookie.Name , cookie.Value );
}
}
示例5: 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);
}
示例6: Add
internal void Add(HttpCookieCollection c)
{
int count = c.Count;
for (int i = 0; i < count; i++)
{
this.ThrowIfMaxHttpCollectionKeysExceeded();
HttpCookie cookie = c.Get(i);
base.Add(cookie.Name, cookie.Value);
}
}
示例7: Gets
private string Gets(HttpCookieCollection cookies)
{
var containsCookie = cookies.AllKeys.Contains(_cookieName);
if (!containsCookie)
{
return null;
}
var cookie = cookies.Get(_cookieName);
return cookie != null ? cookie.Value : null;
}
示例8: CreateParams
public static NameValueCollection CreateParams(NameValueCollection queryString, NameValueCollection form, HttpCookieCollection cookies, NameValueCollection serverVariables)
{
NameValueCollection parms = new NameValueCollection(48);
parms.Add(queryString);
parms.Add(form);
for (var i = 0; i < cookies.Count; i++)
{
var cookie = cookies.Get(i);
parms.Add(cookie.Name, cookie.Value);
}
parms.Add(serverVariables);
return parms;
}
示例9: CookieValueProvider
public CookieValueProvider(HttpCookieCollection cookieCollection)
{
foreach (string cookieName in cookieCollection)
{
var cookie = cookieCollection.Get(cookieName);
foreach (var key in cookie.Values.AllKeys)
{
if (key != null)
_cookiesKeys.Add(key, cookie.Values.Get(key));
}
}
}
示例10: 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));
}
示例11: TryGetRememberedSession
private static RememberedSessions TryGetRememberedSession(EpidaurusDbContainer db, HttpCookieCollection requestCookies)
{
var cookie = requestCookies.Get(CookieName);
if (cookie == null || string.IsNullOrEmpty(cookie.Value))
return null;
var match = Regex.Match(cookie.Value, @"^(.+)_([0-9a-f-]+)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
if (!match.Success)
return null;
string userName = match.Groups[1].Value;
Guid guid;
if (!Guid.TryParse(match.Groups[2].Value, out guid))
return null;
string guidStr = guid.ToString();
return db.RememberedSessions.FirstOrDefault(el => el.User.Username == userName && el.GuidHash == guidStr);
}
示例12: Add
private void Add(NameValueCollection collection, HttpCookieCollection c) {
int n = c.Count;
for(int i = 0; i < n; i++) {
HttpCookie cookie = c.Get(i);
collection.Add(cookie.Name, cookie.Value);
}
}
示例13: ValidateCookieCollection
private void ValidateCookieCollection(HttpCookieCollection cc)
{
int count = cc.Count;
for (int i = 0; i < count; i++)
{
string key = cc.GetKey(i);
string str2 = cc.Get(i).Value;
if (!string.IsNullOrEmpty(str2))
{
this.ValidateString(str2, key, RequestValidationSource.Cookies);
}
}
}
示例14: UpdateTest
public void UpdateTest ()
{
// the msdn examples show updates with col.Set being
// called after a change is made to a cookie. turns
// out this isn't necessary.
HttpCookieCollection col = new HttpCookieCollection ();
HttpCookie cookie1, cookie2;
cookie1 = new HttpCookie ("cookie", "value1");
col.Add (cookie1);
cookie2 = col.Get (cookie1.Name);
cookie2.Value = "value2";
cookie2 = col.Get (cookie1.Name);
Assert.AreEqual ("value2", cookie2.Value, "col.Get doesn't copy");
}
示例15: Get
[Test] // Get (string)
public void Get_Name ()
{
HttpCookieCollection col = new HttpCookieCollection ();
Assert.IsNull (col.Get ("DOESNOTEXIST"), "#1");
HttpCookie cookie1 = new HttpCookie ("cOokiE1", "value1");
col.Add (cookie1);
HttpCookie cookie2 = new HttpCookie ("cOokiE2", "value2");
col.Add (cookie2);
HttpCookie cookie3 = new HttpCookie ("cookie1", "value3");
col.Add (cookie3);
Assert.AreSame (cookie1, col.Get ("cOokiE1"), "#2");
Assert.AreSame (cookie1, col.Get ("cookiE1"), "#3");
Assert.AreSame (cookie2, col.Get ("cOokiE2"), "#4");
Assert.AreSame (cookie2, col.Get ("COOkiE2"), "#5");
Assert.IsNull (col.Get ((string) null), "#6");
Assert.IsNull (col.Get ("DOESNOTEXIST"), "#7");
}