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


C# OSHttpResponse.SetCookie方法代码示例

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


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

示例1: SetAuthCookie

        public static bool SetAuthCookie(OSHttpRequest httpRequest, OSHttpResponse httpResponse, Uri identity, string consumer)
        {
            bool permissionGranted = false;
            HttpCookie cookie = (httpRequest.Cookies != null) ? httpRequest.Cookies["cb_auth"] : null;
            AuthCookie authCookie;
            string cookieKey;

            // Check for an existing cookie pointing to valid server-side cached info
            if (cookie != null && AuthCookies.TryGetValue(cookie.Value, out authCookie))
            {
                cookieKey = cookie.Value;

                // TODO: Linear search could be eliminated with a HashSet<>
                if (authCookie.AuthedRealms.Contains(consumer))
                    permissionGranted = true;
            }
            else
            {
                // Create a new cookie
                cookieKey = UUID.Random().ToString();
                authCookie = new AuthCookie(cookieKey, identity);
            }

            // Cookie will expire in five days
            DateTime cookieExpiration = DateTime.Now + TimeSpan.FromDays(5.0);

            // Set cookie information on the server side and in the client response
            AuthCookies.AddOrUpdate(cookieKey, authCookie, cookieExpiration);

            HttpCookie responseCookie = new HttpCookie("cb_auth", cookieKey);
            responseCookie.Expires = cookieExpiration;
            httpResponse.SetCookie(responseCookie);

            return permissionGranted;
        }
开发者ID:AlphaStaxLLC,项目名称:taiga,代码行数:35,代码来源:CableBeachServerState.cs

示例2: SetCookie

        void SetCookie(OSHttpResponse httpResponse, Uri identity, UserProfileData profile)
        {
            string cookieKey = UUID.Random().ToString();

            // Cookie will expire in five days
            DateTime cookieExpiration = DateTime.Now + TimeSpan.FromDays(5.0);

            // Cache the server-side data
            CableBeachState.AuthCookies.AddOrUpdate(cookieKey, new AuthCookie(cookieKey, identity, profile), cookieExpiration);

            // Create the cookie
            HttpCookie responseCookie = new HttpCookie("cb_openid_auth", cookieKey);
            responseCookie.Expires = cookieExpiration;
            httpResponse.SetCookie(responseCookie);
        }
开发者ID:AlphaStaxLLC,项目名称:taiga,代码行数:15,代码来源:OpenIdHandler.cs


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