Skip to content

Instantly share code, notes, and snippets.

@Maarten88
Last active December 18, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maarten88/5778508 to your computer and use it in GitHub Desktop.
Save Maarten88/5778508 to your computer and use it in GitHub Desktop.
<div id="cookie-alert">
<div class="alert">
<p><strong>Cookies:</strong> please allow us to use cookies for Facebook Like buttons and Google analytics.</p>
<form class="btn-group-vertical" action="@Url.Action("NoCookies", "Site", new { ReturnUrl = Request.RawUrl })" method="post" data-async="true" data-target="#cookie-alert" >
<input type="submit" name="decline" class="btn btn-warning" value="Decline" />
</form>
<form class="btn-group-vertical" action="@Url.Action("AllowCookies", "Site", new { ReturnUrl = Request.RawUrl })" method="post">
<input type="submit" name="allow" class="btn btn-success" value="Allow" />
</form>
</div>
</div>
$('form[data-async=true]').on('submit', function (event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
success: function (data, status) {
$target.html(data);
}
});
event.preventDefault();
});
using Auction.Web.Utility;
using System.Web.Mvc;
namespace Auction.Web.Controllers
{
[AllowAnonymous]
public class SiteController : BaseController
{
public ActionResult AllowCookies(string ReturnUrl)
{
CookieConsent.SetCookieConsent(Response, true);
return RedirectToLocal(ReturnUrl);
}
public ActionResult NoCookies(string ReturnUrl)
{
CookieConsent.SetCookieConsent(Response, false);
// if we got an ajax submit, just return 200 OK, else redirect back
if (Request.IsAjaxRequest())
return new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
else
return RedirectToLocal(ReturnUrl);
}
[OutputCache(Duration = 60 * 60 * 24 * 365, Location = System.Web.UI.OutputCacheLocation.Any)]
public ActionResult FacebookChannel()
{
return View();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment