Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Adding a response cookie from IResourceFilter.OnResourceExecuted doesn't emit Set-Cookie when result is ViewResult #4065

Closed
@rwasef1830

Description

@rwasef1830

Steps to reproduce:

Modify the default ASP.net MVC template so that the home controller looks like this:

    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Redirect()
        {
            return this.RedirectToAction("About");
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }
    }

Add an IResourceFilter:

    public class TestResourceFilter : IResourceFilter
    {
        public void OnResourceExecuting(ResourceExecutingContext context)
        {
            context.HttpContext.Response.Cookies.Append("OnResourceExecuting", "1");
        }

        public void OnResourceExecuted(ResourceExecutedContext context)
        {
            context.HttpContext.Response.Cookies.Append("OnResourceExecuted", "1");
        }
    }

Register it in startup:

public void ConfigureServices(IServiceCollection services)
{
     // ...
     services.AddMvc(o => o.Filters.Add(new TestResourceFilter()));
     // ...
}

Visit /Home/Index:

  • Only the OnResourceExecuting cookie is present in the Set-Cookie header.

Visit /Home/Redirect:

  • The 302 response that returns has both cookies in the Set-Cookie header (OnResourceExecuting and OnResourceExecuted).
  • The 200 response after the redirect (/Home/About) only has OnResourceExecuting.

This bugs breaks using CookieTempDataProvider (I ported https://github.com/brockallen/CookieTempData to MVC 6) because it depends on serializing TempData into a cookie when registered as a ITempDataProvider.

Edit: Forgot to mention, this is with ASP.net 5 / MVC 6 RC1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions