2013-12-12 17:30:27 +11:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
|
using System.Web;
|
2013-06-07 02:29:24 -10:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Extension methods used to check/set cookie values
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// This should 100% supercede the StateManager.Cookies
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
internal static class HttpCookieExtensions
|
|
|
|
|
|
{
|
2013-12-12 17:30:27 +11:00
|
|
|
|
public static string GetPreviewCookieValue(this HttpRequestMessage request)
|
|
|
|
|
|
{
|
|
|
|
|
|
var cookie = request.Headers.GetCookies(Constants.Web.PreviewCookieName).FirstOrDefault();
|
|
|
|
|
|
if (cookie != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cookie[Constants.Web.PreviewCookieName] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return cookie[Constants.Web.PreviewCookieName].Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2013-06-07 02:29:24 -10:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Does a preview cookie exist ?
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static bool HasPreviewCookie(this HttpRequestBase request)
|
|
|
|
|
|
{
|
2013-12-12 17:30:27 +11:00
|
|
|
|
return request.Cookies[Constants.Web.PreviewCookieName] != null;
|
2013-06-07 02:29:24 -10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Does a cookie exist with the specified key ?
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static bool HasCookie(this HttpRequestBase request, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return request.Cookies[key] != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Is there a cookie with the key supplied and does it have a value that is not empty
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static bool HasCookieValue(this HttpRequestBase request, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return request.Cookies[key] != null
|
|
|
|
|
|
&& request.Cookies[key].Value != null
|
|
|
|
|
|
&& request.Cookies[key].Value.IsNullOrWhiteSpace() == false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|