本文整理汇总了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;
}
示例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);
}