-1

I am building an ASP.NET Core MVC app (build v2.1.0).

I want the users of the application (I don't have any authentication, so anyone can be user) to be forced to select a value from a drodownlist (as a partialview or something) and then to be somehow redirected to the "Homepage". Before this action, any other link from the app should not work until they will select something from that dropdownlist.

This way I can ensure that they will select a country for which I will show all data. Eventually, after selection that dropdownlist should be visible in the navbar in order to change that parameter any time.

Also, I need that value to be visible all over the application as a "global" value (Session or something).

1 Answers1

0

Simplest solution: use a cookie to store the country selection. Check for the cookie value in the controller; if it is not set, reroute to the dropdown page where it can be set. If it is, use it however your code needs to.

Writing Cookies

Response.Cookies.Append("country", "us");

Reading Cookies

var cookie = Request.Cookies["country"];
if (String.IsNullOrWhiteSpace(cookie))
{
    return RedirectToAction("ChooseCountry"); // whatever the action name is where they choose the country
}

// rest of code...
Nathan Miller
  • 785
  • 4
  • 11