When I try to pass some value from my controller to Global.asax
the values received in the global are always null.
Controller:
public class LoginController : Controller
{
DataContext db = new DataContext();
public ActionResult Index()
{
MvcApplication M = new MvcApplication()
var U = db.usuarios.single(u=> u.Id == 1);
M.SetCarregarDadosUsuario(U);
}
}
Global:
public class MvcApplication : System.Web.HttpApplication {
public Usuarios usuarioSession = new Usuarios();
protected void Application_AcquireRequestState(){
if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState){
CarregarDadosUsuario();}
}
private void CarregarDadosUsuario(){
if(usuarioSession.Id >0){
var loadU = GetCarregarDadosUsuario();
HttpContext.Current.Session.Add("UsuarioImagem", loadU.UrlImg);
HttpContext.Current.Session.Add("UsuarioNome", loadU.Nome);
HttpContext.Current.Session.Add("UsuarioSessao", loadU.SessaoID);
HttpContext.Current.Session.Add("UsuarioFilial", loadU.FilialID);
}
}
public void SetCarregarDadosUsuario(Usuarios user) {
this.usuarioSession = user;
}
public Usuarios GetCarregarDadosUsuario(){
return this.usuarioSession;
}
}
I would like to know how I can move my Controller to Globlal.asax.cs to fill out my sessions.
Because the purpose of sessions is to add values in the layout file and set permissions to not perform benchmarking at all times. Example:
<div class="user-img-div user-basic basic-perfil-borda">
<img src="/Content/NewTheme/img/@Session["UsuarioImagem"]" class="img-thumbnail" />
</div>