I am making a base controller
that my other controllers
will inherit from and one of the things I want to do is grab the user's IP Address
and check it see if it is the one I want, if it is not I want to redirect them to the home page. I tested the code in a normal controller and it works fine but as soon as I move the code to BaseController
it errors with a Null Reference Exception
. How can I get this to work in my Base Controller?
using FFInfo.WebUI.Controllers;
using System.Web.Mvc;
namespace FFInfo.WebUI.Areas.Admin.Controllers
{
public class AdminBaseController : GlobalBaseController
{
public AdminBaseController()
{
if (HttpContext.Request.ServerVariables["REMOTE_HOST"] != "ValidIP")
{
RedirectToAction("Index", "Home", new { area = "" });
}
}
}
}