I just need to make an manual autentication on MVC3 and the problem is, when the user access the url from project, i have this code on base class:
public class BaseController : Controller
{
private Usuario loggedUser;
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
if (requestContext.HttpContext.Request.RawUrl != "/Home/Login")
{
if (requestContext.HttpContext.Session["usuario"] != null)
{
loggedUser = (Usuario)requestContext.HttpContext.Session["usuario"];
ViewBag.nomeUsuario = loggedUser.Nome;
ViewBag.idUsuario = loggedUser.Id;
}
else
{
requestContext.HttpContext.Response.RedirectPermanent("~/Home/Login");
}
}
base.Initialize(requestContext);
}
The problem is, when they are not authorized I send a redirect BUT the initialize continues to process the request action. I think the validation are on not a good place becouse I can remove the inicalize method.