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


C# IMansionContext.SetCookie方法代码示例

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


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

示例1: DoExecute

        /// <summary>
        /// Executes this tag.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        protected override void DoExecute(IMansionContext context)
        {
            // create the cookie
            var cookie = new WebCookie {
                Name = GetRequiredAttribute<string>(context, "name"),
                HttpOnly = GetAttribute(context, "httpOnly", true),
                Expires = GetAttribute(context, "expires", DateTime.Today.AddDays(30)),
                Value = GetRequiredAttribute<string>(context, "value")
            };

            //  set the cookie
            context.SetCookie(cookie);
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:17,代码来源:SetCookieTag.cs

示例2: DoAuthenticate

        /// <summary>
        /// Authenticates the user.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="authenicationProvider">The authentication provider which to use.</param>
        /// <param name="parameters">The parameters used for authentication.</param>
        /// <returns>Returns the <see cref="AuthenticationResult"/>.</returns>
        protected override AuthenticationResult DoAuthenticate(IMansionContext context, AuthenticationProvider authenicationProvider, IPropertyBag parameters)
        {
            // authenticate
            var result = authenicationProvider.Authenticate(context, parameters);
            if (!result.WasSuccesful)
                return result;
            var user = result.UserState;

            // get the web request context
            var webContext = context.Cast<IMansionWebContext>();

            // check session
            if (!webContext.Session.IsWritable)
                throw new InvalidOperationException("Could not authenticate user because the session is not writeable");

            // store this user in the session
            webContext.Session[GetRevivalCookieName(context)] = user;

            // check if the authentication provider support user revival and the rememberMe flag was set
            var revivalCookieName = GetRevivalCookieName(context);
            if (authenicationProvider.SupportsRevival && parameters.Get(context, "allowRevival", false))
            {
                // get the revival data for this user
                var revivalData = authenicationProvider.GetRevivalProperties(context, user, parameters);
                if (revivalData != null)
                {
                    // add additional revival properties
                    revivalData.Set("authenticationProviderName", authenicationProvider.Name);
                    revivalData.Set("userSignature", GetUserSignatureHash(webContext));

                    // encrypt it
                    var serializedRevivalData = conversionService.Convert<byte[]>(context, revivalData);
                    var encryptedRevivalData = encryptionService.Encrypt(context, cookieSalt, serializedRevivalData);
                    var revivalDataString = conversionService.Convert<string>(context, encryptedRevivalData);

                    // store it in a cookie
                    var revivalCookie = new WebCookie {
                        Name = revivalCookieName,
                        Value = revivalDataString,
                        Expires = DateTime.Now.AddDays(14),
                        HttpOnly = true
                    };
                    context.SetCookie(revivalCookie);
                }
            }
            else
                context.DeleteCookie(revivalCookieName);

            // authentication was successful
            return result;
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:58,代码来源:WebSecurityService.cs


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