This is a really stupid little thing, but I am anally retentive, and when R # (6.1) emphasizes what I usually want to “fix”. I am working on an MVC4 project and passing the identifier value from one controller to another using a cookie. I'm still a little newbie to MVC, so there may be a better way to do this. In any case, I check for the presence of a cookie and then get its value as follows:
var idCookieString = string.Empty;
if(Request.Cookies.AllKeys.Contains("id"))
{
idCookieString = Request.Cookies["id"].Value;
}
The annoyance is that R # raises Request.Cookies["id"]as a possible exception the link, although I check if the cookie exists in the instructions if. Is there a better way to check if a cookie exists before trying to recover it, or should I just put R # on it to ignore?
source
share