diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs index 0c875b2083..57218a9ad9 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Authentication.Cookies OnResponseSignIn = context => { }; OnResponseSignedIn = context => { }; OnResponseSignOut = context => { }; - OnApplyRedirect = DefaultBehavior.ApplyRedirect; + OnApplyRedirect = context => context.Response.Redirect(context.RedirectUri); OnException = context => { }; } diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/DefaultBehavior.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/DefaultBehavior.cs deleted file mode 100644 index 9807bbdf4f..0000000000 --- a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/DefaultBehavior.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -using System; -using Microsoft.AspNet.Http; -using Newtonsoft.Json; - -namespace Microsoft.AspNet.Authentication.Cookies -{ - internal static class DefaultBehavior - { - internal static readonly Action ApplyRedirect = context => - { - if (IsAjaxRequest(context.Request)) - { - var jsonResponse = JsonConvert.SerializeObject(new - { - status = context.Response.StatusCode, - headers = new - { - location = context.RedirectUri - } - }, Formatting.None); - - context.Response.StatusCode = 200; - context.Response.Headers.Append("X-Responded-JSON", jsonResponse); - } - else - { - context.Response.Redirect(context.RedirectUri); - } - }; - - private static bool IsAjaxRequest(HttpRequest request) - { - var query = request.Query; - if (query != null) - { - if (query["X-Requested-With"] == "XMLHttpRequest") - { - return true; - } - } - - var headers = request.Headers; - if (headers != null) - { - if (headers["X-Requested-With"] == "XMLHttpRequest") - { - return true; - } - } - return false; - } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index 5327d8a4a1..42de3e8ad9 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -533,27 +533,11 @@ namespace Microsoft.AspNet.Authentication.Cookies clock.Add(TimeSpan.FromMinutes(4)); - Transaction transaction5 = await SendAsync(server, "http://example.com/me/Cookies", transaction4.CookieNameValue); + var transaction5 = await SendAsync(server, "http://example.com/me/Cookies", transaction4.CookieNameValue); transaction5.SetCookie.ShouldBe(null); FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe("Alice"); } - [Fact] - public async Task AjaxRedirectsAsExtraHeaderOnTwoHundred() - { - var server = CreateServer(options => - { - options.LoginPath = new PathString("/login"); - options.AutomaticAuthentication = true; - }); - - var transaction = await SendAsync(server, "http://example.com/protected", ajaxRequest: true); - transaction.Response.StatusCode.ShouldBe(HttpStatusCode.OK); - var responded = transaction.Response.Headers.GetValues("X-Responded-JSON"); - responded.Count().ShouldBe(1); - responded.Single().ShouldContain("\"location\""); - } - [Fact] public async Task CookieUsesPathBaseByDefault() {