1
In my Account controller, in Action Login, I have the code below:
case "Sucess":
string rule = CheckRule(model.username, model.Password);
Response.SetCookie(SetAuthCookie(model.username, model.RememberMe, rule));
return RedirectToAction("Index", rule);
In checkrule, I return a string with the name of the controller according to the authentication rule, between these names are Admin and Basicuser, below is the code of these controllers:
Admin
{
[Authorize]
public class AdminController : Controller
{
private bool attAuthor = isAuthorized();
private bool attAuth = isAuthenticated();
private string rule = returnrule();
// GET: Admin
public ActionResult Index()
{
if (!attAuthor)
{
return RedirectToAction("erro401",rule);
}
else
{
return View();
}
}
public ActionResult erro401()
{
return View("erro401");
}
}
and Basicuser:
{
[Authorize]
public class BasicUserController : Controller
{
private bool attAuthor = isAuthorized();
private bool attAuth = isAuthenticated();
private string rule = returnrule();
// GET: BasicUser
public ActionResult Index()
{
if (!attAuthor)
{
return RedirectToAction("erro401", rule);
}
else
{
FormsAuthenticationTicket authticket = get_ticket();
string str = rule + " / " + authticket.Name;
ViewBag.Htmlstr = str;
return View();
}
}
public ActionResult erro401()
{
return View("erro401");
}
}
}
In the code of Route config:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "BasicUser",
url: "{controller}/{action}/{id}",
defaults: new { controller = "BasicUser", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Admin",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Admin", action = "Index", id = UrlParameter.Optional }
);
If I log in with Admin user it works , but if I log in with a basicuser the browser does not redirect, it simply stays on the login screen, but if I type in the address bar it goes to the right page. I added a tag in the basicuser’s Index.cshtml to see the rule that appears in the cookie, and the right rule appears, only it is not redirecting to the controller page .
I’m sorry if I haven’t been very clear, I’m very Newbie yet...
Follow the link with the answers of the question in English: Response of the Stack in English
– Rogério Ferreira