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


C# IMansionContext.DeleteCookie方法代码示例

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


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

示例1: DoExecute

 /// <summary>
 /// Executes this tag.
 /// </summary>
 /// <param name="context">The <see cref="IMansionContext"/>.</param>
 protected override void DoExecute(IMansionContext context)
 {
     // clear the cookie
     context.DeleteCookie(GetRequiredAttribute<string>(context, "name"));
 }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:9,代码来源:ClearCookieTag.cs

示例2: InitializeUserFromCookie

        /// <summary>
        /// Tries to revive the user from cookie.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="cookieName">The name of the cookie from which to revive the user.</param>
        /// <returns>Returns the revived user or null.</returns>
        private UserState InitializeUserFromCookie(IMansionContext context, string cookieName)
        {
            // get the web request context
            var webContext = context.Cast<IMansionWebContext>();

            // check sesssion
            if (!webContext.Session.IsReadable)
                return null;
            var sessionUser = webContext.Session[cookieName] as UserState;
            if (sessionUser != null)
                return sessionUser;

            // check for revival cookie
            WebCookie revivalCookie;
            if (!webContext.Request.Cookies.TryGetValue(cookieName, out revivalCookie) || string.IsNullOrEmpty(revivalCookie.Value))
                return null;

            // deserialize the properties
            var revivalDataStringBytes = conversionService.Convert<byte[]>(context, revivalCookie.Value);
            byte[] decryptedRevivalDataBytes;
            try
            {
                decryptedRevivalDataBytes = encryptionService.Decrypt(context, cookieSalt, revivalDataStringBytes);
            }
            catch (CryptographicException)
            {
                // cookie contains invalid hash
                context.DeleteCookie(cookieName);
                return null;
            }
            var revivalProperties = conversionService.Convert<IPropertyBag>(context, decryptedRevivalDataBytes, new PropertyBag());

            // check against cookie theft
            var currentUserSignature = GetUserSignatureHash(webContext);
            var cookieUserSignature = revivalProperties.Get(context, "userSignature", string.Empty);
            if (!cookieUserSignature.Equals(currentUserSignature))
            {
                context.DeleteCookie(cookieName);
                return null;
            }

            // get the authentication provider
            String authenticationProviderName;
            if (!revivalProperties.TryGetAndRemove(context, "authenticationProviderName", out authenticationProviderName) || string.IsNullOrEmpty(authenticationProviderName))
            {
                context.DeleteCookie(cookieName);
                return null;
            }
            AuthenticationProvider authenticationProvider;
            if (!TryResolveAuthenticationProvider(context, authenticationProviderName, out authenticationProvider))
            {
                context.DeleteCookie(cookieName);
                return null;
            }

            // try to revive the user
            var revivedUser = authenticationProvider.ReviveUser(context, revivalProperties);
            if (revivedUser == null)
                context.DeleteCookie(cookieName);
            return revivedUser;
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:67,代码来源:WebSecurityService.cs

示例3: 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

示例4: DoLogoff

        /// <summary>
        /// Logs the user of from the current request context.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="authenicationProvider">The authentication provider which to use.</param>
        protected override void DoLogoff(IMansionContext context, AuthenticationProvider authenicationProvider)
        {
            // authenticate
            authenicationProvider.Logoff(context);

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

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

            // clear the user from the session
            webContext.Session.Remove(GetRevivalCookieName(context));

            // delete any revival cookies
            context.DeleteCookie(GetRevivalCookieName(context));
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:23,代码来源:WebSecurityService.cs


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