locked
Cannot Append to cookie in ASP.NET Core 2.0 RRS feed

  • Question

  • Hello,

    I am trying perform a very simple action

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;

                    var mtaUserCookie = Request.Cookies["mtaUserRole"];
                    if (mtaUserCookie != null)
                    {
                        Response.Cookies.Delete("mtaUserRole");
                    }
                    try
                    {
                        var cookieName = "mtaUserRole";
                        Response.Cookies.Append(cookieName, "IsAppAdmin");
                    }
                    catch ( Exception e ){ e.Message.ToString(); }  // no errors...

                    // debug code
                    mtaUserCookie = Request.Cookies["mtaUserRole"];  // Receive "Object not set to an instance of an Object" here

    Please help.



    • Edited by ralphb1109 Friday, March 9, 2018 6:51 PM
    • Moved by Fei Hu Monday, March 12, 2018 2:02 AM Moved from C#
    Friday, March 9, 2018 6:50 PM

All replies

  • This is not a C# language question. I think you will get the best help from experts in that topic in the ASP.NET Forums.


    Sam Hobbs
    SimpleSamples.Info

    Friday, March 9, 2018 7:20 PM
  • Thank you. I have moved this there and tried to delete it from here.

    Friday, March 9, 2018 8:24 PM