當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。