nikmd23 / CourtesyFlush

The source for my CourtesyFlush NuGet package.
Apache License 2.0
72 stars 6 forks source link

Fall back to AntiForgeryToken if FlushedAntiForgeryToken does not exist #16

Closed drayfar closed 8 years ago

drayfar commented 9 years ago

Hey @nikmd23 - really liking this package, thanks for the hard work! I have some partial views in my solution which are sometimes rendered inline on a page (and thus have the head flushed), and are sometimes rendered outside of a page via AJAX (and thus do not have the head flushed). Because of this, I need to use the FlushedAntiForgeryToken only some of the time. Do you see any problem with updating the code to fall back to AntiForgeryToken if FlushedAntiForgeryToken is not present?

I tested this with the following additional extension in my code:

    public static MvcHtmlString FallbackAntiForgeryToken(this HtmlHelper html)
        {
            var token = html.ViewContext.HttpContext.Items["_FlushedAntiForgeryToken"] as string;
            if (!string.IsNullOrEmpty(token))
            {
                return html.FlushedAntiForgeryToken();
            }

            return html.AntiForgeryToken();
        }

I'm happy to submit a pull request if you don't see an issue with this. Thanks!

nikmd23 commented 9 years ago

Hey @drayfar!

I'm glad you like the package and have found it useful.

I'm certainly interested in pulling this in. Please just submit the PR, and add a comment showing usage & why/when someone would use.

drayfar commented 9 years ago

Just submitted the pull request, sorry for the delay.

nikmd23 commented 8 years ago

Awesome.

Would you like to test everything now that it's merged, and I'll try to get 1.3.0 out ASAP?