当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponseBase.SetCookie方法代码示例

本文整理汇总了C#中System.Web.HttpResponseBase.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.SetCookie方法的具体用法?C# HttpResponseBase.SetCookie怎么用?C# HttpResponseBase.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpResponseBase的用法示例。


在下文中一共展示了HttpResponseBase.SetCookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetCurrentCultureCookie

 public static void SetCurrentCultureCookie(HttpResponseBase response, string cultureName)
 {
     if (_s_supportedCultures.Any(item => item.Value == cultureName))
       {
     response.SetCookie(new HttpCookie(CultureCookieName, cultureName) { HttpOnly = true });
       }
 }
开发者ID:PaloMraz,项目名称:AspNetMvcLocalizedApp,代码行数:7,代码来源:LocalizationFilterAttribute.cs

示例2: SetKey

 public void SetKey(HttpRequestBase request, HttpResponseBase response, string sessionKey)
 {
     var cookie = new HttpCookie("sessionId", sessionKey);
     cookie.Expires = DateTime.Now.AddMinutes(15);
     cookie.Path = "/";
     response.SetCookie(cookie);
 }
开发者ID:nixondanielj,项目名称:chess3,代码行数:7,代码来源:AuthHelper.cs

示例3: ManageLanguageCookie

        /// <summary>
        /// This takes the language code (from url) and makes sure the cookie is set accordingly.
        /// </summary>
        /// <param name="langCode"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public static void ManageLanguageCookie(string langCode, HttpResponseBase response)
        {
            // Get the cookie
            var languageCookie = HttpContext.Current.Request.Cookies["Language"];
            if (languageCookie == null)
            {
                languageCookie = new HttpCookie("Language"); // Create if needed
            }

            languageCookie.Value = langCode;
            languageCookie.Expires = DateTime.Now.AddDays(10);
            response.SetCookie(languageCookie);
        }
开发者ID:sebastienricher,项目名称:SectionG,代码行数:19,代码来源:Utilities.cs

示例4: SetCookie

        /// <summary>
        /// Creates or updates a cookie in the cookie collection.
        /// </summary>
        /// <param name="httpResponse">The HTTP response to set the cookie for.</param>
        /// <param name="cookieName">The name of the cookie.</param>
        /// <param name="cookieValue">The value of the cookie.</param>
        /// <exception cref="ArgumentNullException"><paramref name="httpResponse"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="cookieName"/> is <c>null</c>, empty, or white space.</exception>
        public static void SetCookie(HttpResponseBase httpResponse, string cookieName, string cookieValue)
        {
            /* TODO Parameterize the cookie expiration date (now hard-coded to 1 year).
             * Steven Volckaert. January 16, 2013.
             */

            if (httpResponse == null)
                throw new ArgumentNullException("httpResponse");

            if (String.IsNullOrWhiteSpace(cookieName))
                throw new ArgumentException("The parameter is null or empty.", "cookieName");

            var cookie = string.IsNullOrEmpty(cookieValue)
                ? new HttpCookie(cookieName)
                : new HttpCookie(cookieName, cookieValue);

            cookie.Expires = DateTime.Now.AddYears(1);
            httpResponse.SetCookie(cookie);
        }
开发者ID:stevenvolckaert,项目名称:autodesk-inventor-powertools,代码行数:27,代码来源:CookieManager.cs

示例5: SetAuthCooke

        public static void SetAuthCooke(HttpResponseBase response, int userId, string guid, int minutes = 60)
        {
            if(userId < 1 || guid == null)
            {
                return;
            }

            var cookie = new HttpCookie(Constants.COOKIE_AUTH)
            {
                Value = Helpers.CEncode(guid + ":" + userId),
                Expires = DateTime.Now.AddMinutes(minutes)
            };
            response.SetCookie(cookie);
        }
开发者ID:dedabyte,项目名称:ScrapNews,代码行数:14,代码来源:Auth.cs

示例6: SetUserMode

 public void SetUserMode(HttpResponseBase response, UserMode userMode)
 {
     HttpCookie modeCookie = new HttpCookie("CurrentMode", userMode.ToString());
     response.SetCookie(modeCookie);
 }
开发者ID:mastoj,项目名称:NBlog,代码行数:5,代码来源:AuthenticationService.cs

示例7: AuthenticateUser

 public void AuthenticateUser(HttpResponseBase response)
 {
     var token = protector.Protect(this.AuthToken());
     response.SetCookie(new HttpCookie(cookieid, token));
 }
开发者ID:BeeFrog,项目名称:dashing.net,代码行数:5,代码来源:SimpleAuthentication.cs

示例8: ClearCookie

		public void ClearCookie(HttpResponseBase resp)
		{
			if (resp == null) throw new ArgumentNullException("resp");
			resp.SetCookie(new HttpCookie(CookieName, null) { Expires = new DateTime(2010,1,1) });
		}
开发者ID:Deson621,项目名称:MvcPowerTools,代码行数:5,代码来源:IpTracking.cs

示例9: ApplyCookies

        /// <summary>
        /// Apply cookies of the CommandResult to the response.
        /// </summary>
        /// <param name="commandResult">Commandresult</param>
        /// <param name="response">Response</param>
        public static void ApplyCookies(this CommandResult commandResult, HttpResponseBase response)
        {
            if(commandResult == null)
            {
                throw new ArgumentNullException(nameof(commandResult));
            }

            if(response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (!string.IsNullOrEmpty(commandResult.SetCookieName))
            {
                var protectedData = HttpRequestData.ConvertBinaryData(
                        MachineKey.Protect(
                            commandResult.GetSerializedRequestState(),
                            HttpRequestBaseExtensions.ProtectionPurpose));

                response.SetCookie(new HttpCookie(
                    commandResult.SetCookieName,
                    protectedData)
                {
                    HttpOnly = true
                });
            }

            if (!string.IsNullOrEmpty(commandResult.ClearCookieName))
            {
                response.SetCookie(new HttpCookie(commandResult.ClearCookieName)
                {
                    Expires = new DateTime(1970, 01, 01)
                });
            }
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:40,代码来源:CommandResultHttpExtension.cs

示例10: Save

        public void Save(HttpResponseBase response)
        {
            var cookie = ToHttpCookie();
            cookie.Expires = DateTime.UtcNow.AddYears(10);

            response.SetCookie(cookie);
        }
开发者ID:Mavtak,项目名称:roomie,代码行数:7,代码来源:CacheCookie.cs

示例11: ApplyCookies

        /// <summary>
        /// Apply cookies of the CommandResult to the response.
        /// </summary>
        /// <param name="commandResult">Commandresult</param>
        /// <param name="response">Response</param>
        public static void ApplyCookies(this CommandResult commandResult, HttpResponseBase response)
        {
            if(commandResult == null)
            {
                throw new ArgumentNullException(nameof(commandResult));
            }

            if(response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (!string.IsNullOrEmpty(commandResult.SetCookieName))
            {
                var protectedData = HttpRequestData.EscapeBase64CookieValue(
                    Convert.ToBase64String(
                        MachineKey.Protect(
                            Encoding.UTF8.GetBytes(commandResult.SetCookieData),
                            "Kentor.AuthServices")));

                response.SetCookie(new HttpCookie(
                    commandResult.SetCookieName,
                    protectedData)
                {
                    HttpOnly = true
                });
            }

            if (!string.IsNullOrEmpty(commandResult.ClearCookieName))
            {
                response.SetCookie(new HttpCookie(commandResult.ClearCookieName)
                {
                    Expires = new DateTime(1970, 01, 01)
                });
            }
        }
开发者ID:johansvard,项目名称:authservices,代码行数:41,代码来源:CommandResultHttpExtension.cs

示例12: UpdateAuthCookie

        protected void UpdateAuthCookie(HttpResponseBase Response, HttpCookie cookie)
        {
            SimpleAuthenticationTicket ticket = SimpleAuthenticationTicket.Decrypt(cookie.Value);

            if (ticket == null)
            {
                return;
            }

            //Если KeepLoggedIn, то продляем
            if (ticket.KeepLoggedIn)
            {
                ticket.ExpirationDate = DateTime.Now.AddDays(SettingsManager.AuthenticationSettings.DaysToExpiration);
                cookie.Expires = ticket.ExpirationDate;
            }

            cookie.Value = ticket.Encrypt();

            Response.SetCookie(cookie);
        }
开发者ID:RepetitX,项目名称:SimpleMVCAuthentication,代码行数:20,代码来源:SimpleAuthenticationHandler.cs

示例13: SetCookies

        public void SetCookies(HttpResponseBase Response, User User, bool KeepLoggedIn)
        {
            HttpCookie cookie = CreateAuthCookie(User, KeepLoggedIn);
            Response.SetCookie(cookie);

            cookie = CreateSessionCookie(User);
            if (cookie != null)
            {
                Response.SetCookie(cookie);
            }
        }
开发者ID:RepetitX,项目名称:SimpleMVCAuthentication,代码行数:11,代码来源:SimpleAuthenticationHandler.cs

示例14: RemoveMessage

 public static void RemoveMessage(HttpResponseBase response)
 {
     HttpCookie cookie = new HttpCookie("SystemMessage");
     cookie.Expires = DateTime.Now.AddDays(-1);
     response.SetCookie(cookie);
 }
开发者ID:junex28,项目名称:quan-ly-do-dac,代码行数:6,代码来源:MessageHelper.cs

示例15: CreateMessage

 public static void CreateMessage(MessageType messageType, string messageTitle, List<string> messageDetails, HttpResponseBase response)
 {
     MessageModel message = new MessageModel(messageType, messageTitle, messageDetails);
     response.SetCookie(new HttpCookie("SystemMessage", SerializationHelper.Serialization<MessageModel>(message)));
 }
开发者ID:junex28,项目名称:quan-ly-do-dac,代码行数:5,代码来源:MessageHelper.cs


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