0
I have a problem in my application ASP.Net MVC
, on authentication. Let’s go through steps:
1) I have my login screen /Login/Index
simply log in, if found in the database MySQL
, and starts the session and redirects to /Dashboard/Index
. This is the user verification code and if it correctly starts the session:
[Note:] I use object SessionManager
Generic and a ISessionOperation
with methods that Start
, Finish
, IsActive
, GetSessionId
, GetUsuario
.
Follow the code below the Action Login HttpPost
:
[HttpPost]
public ActionResult Logar(UsuarioDto Model, string Remind)
{
try
{
var UsuarioLogado = UsuarioDomain.Authentication(Model);
if (UsuarioLogado != null)
{
//--> Acesso
var AcessoDomain = new SmartAdmin.Domain.Acesso();
AcessoDomain.Save(GetUserInformation(String.Empty));
//--> Menus & Submenus
var CollectionMenuMain = new List<MenuModelView>();
foreach (var MenuMain in UsuarioDomain.GetAllowedMenus(UsuarioLogado.ID)) //--> Para cada menu pai pega os filhos e adiciona no modelo de visão
{
var CollectionSubMenus = UsuarioDomain.GetSubMenuFromMenu(MenuMain.ID);
var CurrentMenuMain = new MenuModelView() { Menu = MenuMain, CollectionSubMenu = CollectionSubMenus };
CollectionMenuMain.Add(CurrentMenuMain);
}
//--> Session
var Session = new SessionManager();
Session.Start(new UsuarioModelView() { Usuario = UsuarioLogado, CollectionMenusAndSubMenus = CollectionMenuMain });
return (RedirectToAction("Index", "Menu"));
}
else
{
TempData["Mensagem"] = "Usuário inexistente ou não esta ativo no sistema, contate o Administrador!";
return (RedirectToAction("Index", "Login"));
}
}
catch (Exception Ex)
{
throw new Exception(Ex.Message);
}
}
2) The second issue is that I deal with all Actions
of my application with ActionFilter
or created a ActionFilter
that checks if the session is active. If it is not redirected to /Login/Index
. If active, access to Action
call, follow the example of my ActionFilter
what use:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var Session = new SessionManager();
if (Session.IsActive() == false)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
{
controller = "Login",
action = "Index"
}));
}
I use it this way in mine Actions
within the majority of controllers
of my application, a common thing to use ok.
[AuthorizedUser]
public ActionResult Cedente()
{
var CedenteDomain = new Cedente();
var Model = CedenteDomain.GetItem(_ => _.ID == 1);
ViewBag.Mensagem = (TempData["Mensagem"] as String);
return View((Model==null)?new CedenteDto(): Model);
}
3) Let’s get to the problem! , Next, this developing, local in my Visual Studio 2012
, and even the IIS7
configured location
is working properly parametrizei in the webconfig
sessionTimeOut
to 60 as well. But the bigger problem is that
when I compile and put it on my hosting domain and try to log it properly but when I click on internal links
within my application it redirects to the /Login/Index page I don’t know why and recently clicked with the button
mouse right on an internal link and have opened in new tab and it clicked correctly, the question is, when soon and click
in any ex menu:
Financial
- 1 - Tickets 2 - Transferor 3 - Cash
It redirects to Login/Index, but when ordered to open in new tab by Chrome for example it loads correctly, sometimes it redirects also to Login/Index
.
This all doesn’t happen locally.
4) I searched the internet and saw what to use Session
is very bad tals in order I won’t go into detail an alternative would be to use Cache but the objective question would be how to solve it. Detail all my menu Urls are configured @Url.Action('~/Controller/Action')
I believe you are rightly.
Why not use the standard Asp.net mvc ? Identity
– Rod