• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cookie类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Cookie的典型用法代码示例。如果您正苦于以下问题:C# Cookie类的具体用法?C# Cookie怎么用?C# Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Cookie类属于命名空间,在下文中一共展示了Cookie类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DeleteCookie

 /// <summary>
 /// Delete a cookie in the browser by passing in a copy of a cookie
 /// </summary>
 /// <param name="cookie">An object that represents a copy of the cookie that needs to be deleted</param>
 public void DeleteCookie(Cookie cookie)
 {
     if (cookie != null)
     {
         this.DeleteCookieNamed(cookie.Name);
     }
 }
开发者ID:draculavlad,项目名称:selenium,代码行数:11,代码来源:RemoteCookieJar.cs


示例2: GetFormsCredentials

 public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
 {
     // not use FormsCredentials unless you have implements a custom autentication.
     authCookie = null;
     user = password = authority = null;
     return false;
 }
开发者ID:menasbeshay,项目名称:ivalley-svn,代码行数:7,代码来源:CustomReportCredentials.cs


示例3: GetCookies_AddCookiesWithImplicitDomain_CookiesReturnedOnlyForExactDomainMatch

        public void GetCookies_AddCookiesWithImplicitDomain_CookiesReturnedOnlyForExactDomainMatch()
        {
            const string SchemePrefix = "http://";
            const string OriginalDomain = "contoso.com";

            var container = new CookieContainer();
            var cookie1 = new Cookie(CookieName1, CookieValue1);
            var cookie2 = new Cookie(CookieName2, CookieValue2) { Version = 1 };
            var uri = new Uri(SchemePrefix + OriginalDomain);
            container.Add(uri, cookie1);
            container.Add(uri, cookie2);

            var cookies = container.GetCookies(uri);
            Assert.Equal(2, cookies.Count);
            Assert.Equal(OriginalDomain, cookies[CookieName1].Domain);
            Assert.Equal(OriginalDomain, cookies[CookieName2].Domain);

            uri = new Uri(SchemePrefix + "www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);

            uri = new Uri(SchemePrefix + "x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);

            uri = new Uri(SchemePrefix + "y.x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);

            uri = new Uri(SchemePrefix + "z.y.x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:33,代码来源:CookieContainerTest.cs


示例4: GetFormsCredentials

 public bool GetFormsCredentials(out Cookie authCookie, out string user,
  out string password, out string authority)
 {
     authCookie = null;
     user = password = authority = null;
     return false;
 }
开发者ID:di3goandres,项目名称:02_Experimento,代码行数:7,代码来源:ReportCredentials.cs


示例5: AddAuthenticationCookies

    private static void AddAuthenticationCookies(HttpContext context, System.Net.HttpWebRequest req)
    {
        // Copy user identity to new cookie
        if (context.User != null && context.User.Identity != null)
        {
            var cookiesString0 = req.Headers[HttpRequestHeader.Cookie];
            var cookies = CookieParser.Parse(cookiesString0).ToList();

            // Pass username
            var userCookie = new Cookie("") { Name = "username", Value = context.User.Identity.Name };
            cookies.Add(userCookie);// Always add because this

            // Pass user groups
            var windowsIdentity = context.User.Identity as System.Security.Principal.WindowsIdentity;
            var groupNames = new string[] { };
            if (windowsIdentity.Groups != null)
                groupNames = windowsIdentity.Groups.Select(g => g.Translate(typeof(System.Security.Principal.NTAccount)).Value).ToArray();
            var groupsCookie = new Cookie("") { Name = "usergroups", Value = string.Join(",", groupNames) };
            cookies.Add(groupsCookie);

            // Authentication ticket
            var ticket = TicketHandler.IssueTicket();
            var ticketCookie = new Cookie("") { Name = "winauthticket", Value = ticket };
            cookies.Add(ticketCookie);

            var cookiesString = CookieParser.ToString(cookies.ToArray());
            req.Headers[HttpRequestHeader.Cookie] = cookiesString;
        }
    }
开发者ID:magenta-aps,项目名称:iis_reverse_proxy,代码行数:29,代码来源:RewriteHandler.cs


示例6: GetCookies_AddCookieVersion0WithExplicitDomain_CookieReturnedForDomainAndSubdomains

        public void GetCookies_AddCookieVersion0WithExplicitDomain_CookieReturnedForDomainAndSubdomains()
        {
            const string SchemePrefix = "http://";
            const string OriginalDomain = "contoso.com";

            var container = new CookieContainer();
            var cookie1 = new Cookie(CookieName1, CookieValue1) { Domain = OriginalDomain };
            container.Add(new Uri(SchemePrefix + OriginalDomain), cookie1);

            var uri = new Uri(SchemePrefix + OriginalDomain);
            var cookies = container.GetCookies(uri);
            Assert.Equal(1, cookies.Count);
            Assert.Equal(OriginalDomain, cookies[CookieName1].Domain);

            uri = new Uri(SchemePrefix + "www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(1, cookies.Count);

            uri = new Uri(SchemePrefix + "x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(1, cookies.Count);

            uri = new Uri(SchemePrefix + "y.x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(1, cookies.Count);

            uri = new Uri(SchemePrefix + "z.y.x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(1, cookies.Count);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:30,代码来源:CookieContainerTest.cs


示例7: Ctor_NameValuePath_Success

 public static void Ctor_NameValuePath_Success()
 {
     Cookie c = new Cookie("hello", "goodbye", "foo");
     Assert.Equal("hello", c.Name);
     Assert.Equal("goodbye", c.Value);
     Assert.Equal("foo", c.Path);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:CookieTest.cs


示例8: CookieJar_Example_Weighted

        public void CookieJar_Example_Weighted(int total, int choc1, int choc2, int expectedNumerator, int expectedDenominator)
        {
            // Given we have 2 jars
            // jar one contains 10 choc and 30 vanilla
            // jar two contains 20 choc and 20 vanilla
            // what is the probability of drawing a 
            // vanilla cookie from jar 1

            var sample1 = new WeightedSample<Cookie>("Jar1");
            var sample2 = new WeightedSample<Cookie>("Jar2");
            var hypos = new HypoSet<Cookie>("All");

            hypos.Add(sample1, sample2);

            var chocx = new Cookie() { F = 'C' };
            var vanix = new Cookie() { F = 'V' };

            var choc = It.Is(chocx);
            var vani = It.Is(vanix);

            sample1[chocx] = choc1;
            sample1[vanix] = total - choc1;
            sample2[chocx] = choc2;
            sample2[vanix] = total - choc2;

            sample1.ProbabilityOfEvent(choc);
            sample2.ProbabilityOfEvent(choc);

            var postProb = hypos.PosterierProbability(sample1, vani);

            Assert.That(postProb.Numerator, Is.EqualTo(expectedNumerator));
            Assert.That(postProb.Denominator, Is.EqualTo(expectedDenominator));
        }
开发者ID:roberino,项目名称:linqinfer,代码行数:33,代码来源:HypoSetTests.cs


示例9: HTTPWrapper

 public HTTPWrapper(Cookie sharedCookie)
 {
     UseGZip = true;
     UseProxy = false;
     lastReq = new LastRequest();
     cookies = sharedCookie;
     retries = DEFAULT_RETRIES;
 }
开发者ID:MrPebbles,项目名称:HTTPWrapper-csharp,代码行数:8,代码来源:HTTPWrapper.cs


示例10: CookiePortTest

 public CookiePortTest()
 {
     _cc = new CookieContainer();
     _cookie = new Cookie("name", "value1", "/path", "localhost");
     // use both space and comma as delimiter
     _cookie.Port = "\"80 110,1050, 1090 ,1100\"";
     _cc.Add(new Uri("http://localhost/path"), _cookie);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:CookiePortTest.cs


示例11: CommentUri_GetSet_Success

        public static void CommentUri_GetSet_Success()
        {
            Cookie c = new Cookie();
            Assert.Null(c.CommentUri);

            c.CommentUri = new Uri("http://hello.com");
            Assert.Equal(new Uri("http://hello.com"), c.CommentUri);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:CookieTest.cs


示例12: ShouldAddCookie

 public void ShouldAddCookie()
 {
     driver.Get(macbethPage);
     Cookie cookie = new Cookie("cookie", "monster");
     driver.Manage().AddCookie(cookie);
     Assert.That(driver.Manage().GetCookies().ContainsKey(cookie.Name),
         "Cookie was not added successfully");
 }
开发者ID:santiycr,项目名称:selenium,代码行数:8,代码来源:CookieTest.cs


示例13: OnAuthRequestFinished

        void OnAuthRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            AuthRequest = null;
            string failReason = string.Empty;

            switch (req.State)
            {
                // The request finished without any problem.
                case HTTPRequestStates.Finished:
                    if (resp.IsSuccess)
                    {
                        Cookie = resp.Cookies != null ? resp.Cookies.Find(c => c.Name.Equals(".ASPXAUTH")) : null;

                        if (Cookie != null)
                        {
                            HTTPManager.Logger.Information("CookieAuthentication", "Auth. Cookie found!");

                            if (OnAuthenticationSucceded != null)
                                OnAuthenticationSucceded(this);

                            // return now, all other paths are authentication failures
                            return;
                        }
                        else
                            HTTPManager.Logger.Warning("CookieAuthentication", failReason = "Auth. Cookie NOT found!");
                    }
                    else
                        HTTPManager.Logger.Warning("CookieAuthentication", failReason = string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
                                                        resp.StatusCode,
                                                        resp.Message,
                                                        resp.DataAsText));
                    break;

                // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
                case HTTPRequestStates.Error:
                    HTTPManager.Logger.Warning("CookieAuthentication", failReason = "Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
                    break;

                // The request aborted, initiated by the user.
                case HTTPRequestStates.Aborted:
                    HTTPManager.Logger.Warning("CookieAuthentication", failReason = "Request Aborted!");
                    break;

                // Ceonnecting to the server is timed out.
                case HTTPRequestStates.ConnectionTimedOut:
                    HTTPManager.Logger.Error("CookieAuthentication", failReason = "Connection Timed Out!");
                    break;

                // The request didn't finished in the given time.
                case HTTPRequestStates.TimedOut:
                    HTTPManager.Logger.Error("CookieAuthentication", failReason = "Processing the request Timed Out!");
                    break;
            }

            if (OnAuthenticationFailed != null)
                OnAuthenticationFailed(this, failReason);
        }
开发者ID:ideadreamDefy,项目名称:Defy,代码行数:57,代码来源:SampleCookieAuthentication.cs


示例14: HttpResponseState

 public HttpResponseState(HttpStatusCode statusCode, string statusDescription, Uri requestUrl, Header[] headers, Cookie[] cookies, string contentType)
 {
     StatusCode = statusCode;
     StatusDescription = statusDescription;
     RequestUrl = requestUrl;
     Headers = headers;
     Cookies = cookies;
     ContentType = contentType;
 }
开发者ID:ChrisMissal,项目名称:SpeakEasy,代码行数:9,代码来源:HttpResponseState.cs


示例15: Save

 public void Save(Cookie cookie)
 {
     if (Response.Cookies.AllKeys.Contains(cookie.Name)) {
             // Class was not designed to handle multiple Saves()
             // Need it? _You_ implement it!
             throw new Exception("Cookie has already been saved this session.");
         }
         Response.Cookies.Add(cookie.HttpCookie());
 }
开发者ID:RyanShaul,项目名称:dig,代码行数:9,代码来源:HttpCookieStore.cs


示例16: ProcessCookie

 private static Dictionary<string, object> ProcessCookie(Cookie singleCookie)
 {
     Dictionary<string, object> rawCookie = new Dictionary<string, object>();
     rawCookie.Add("name", singleCookie.Name);
     rawCookie.Add("value", singleCookie.Value);
     rawCookie.Add("path", singleCookie.Path);
     rawCookie.Add("domain", singleCookie.Domain);
     rawCookie.Add("secure", singleCookie.Secure);
     return rawCookie;
 }
开发者ID:jimevans,项目名称:strontium,代码行数:10,代码来源:GetAllCookiesHandler.cs


示例17: Add_CookieVersion1AndRootDomainWithNoLeadingDot_ThrowsCookieException

        public void Add_CookieVersion1AndRootDomainWithNoLeadingDot_ThrowsCookieException()
        {
            const string SchemePrefix = "http://";
            const string OriginalDomain = "contoso.com";

            var container = new CookieContainer();
            var cookie = new Cookie(CookieName1, CookieValue1) { Version = 1, Domain = OriginalDomain };
            var uri = new Uri(SchemePrefix + OriginalDomain);
            Assert.Throws<CookieException>(() => container.Add(uri, cookie));
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:CookieContainerTest.cs


示例18: Comment_GetSet_Success

        public static void Comment_GetSet_Success()
        {
            Cookie c = new Cookie();
            Assert.Equal(string.Empty, c.Comment);

            c.Comment = "hello";
            Assert.Equal("hello", c.Comment);

            c.Comment = null;
            Assert.Equal(string.Empty, c.Comment);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:CookieTest.cs


示例19: CookiePropertiesAreSetWhenInitializedThroughCtor

        public void CookiePropertiesAreSetWhenInitializedThroughCtor()
        {
            // Arrange
            var cookie = new Cookie("name", "value", "www.foo.com", "/");

            // Assert
            Assert.Equal("name", cookie.Name);
            Assert.Equal("value", cookie.Value);
            Assert.Equal("www.foo.com", cookie.Domain);
            Assert.Equal("/", cookie.Path);
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:11,代码来源:CookieFacts.cs


示例20: HttpOnly_GetSet_Success

        public static void HttpOnly_GetSet_Success()
        {
            Cookie c = new Cookie();
            Assert.False(c.HttpOnly);

            c.HttpOnly = true;
            Assert.True(c.HttpOnly);

            c.HttpOnly = false;
            Assert.False(c.HttpOnly);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:CookieTest.cs



注:本文中的Cookie类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CookieContainer类代码示例发布时间:2022-05-24
下一篇:
C# ConwayMaxwellPoisson类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap