How to set default initialization cookie in ASP.NET MVC

I was wondering if anyone could shed some light on managing cookies. More specifically, I would like to know how I can create an initial cookie when a user starts a session on a website.

It is currently ASP.NET_SessionId cookielocated on user computers when moving to a domain. I would like to set up an additional cookie with details languageidand countryiddefault settings when the user first visits the site.

Does anyone know if there is any technique for this, for example, through web.config to configure or place cookie data using layout.cshtml, for example

Response.Cookies["language"].Value = "1";

Response.Cookies["country"].Value= "7";

or similar ?, any option would be appreciated.

+3
source share
2

:

public class LocalizationAwareAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var httpContext = filterContext.HttpContext.Current;

        if (!httpContext.Cookies.Keys.Contains("language"))
        {
            httpContext.Response.AppendCookie(new HttpCookie("language", 1));
        }
        if (!httpContext.Cookies.Keys.Contains("country"))
        {
            httpContext.Response.AppendCookie(new HttpCookie("country", 7));
        }
    }
}

, , .

+3

ASP.NET MVC, , , Global.asax , . HttpContext cookie, , . .

+3

All Articles