// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { DependencyInjectionConfig.AddScope(services); //se agrega el context con un string base en appsettings StringFactory.SetStringEmpresas(Configuration.GetConnectionString("EmpresasString")); services.AddDbContext <EmpresasContext>(options => options.UseSqlServer(StringFactory.StringEmpresas)); StringFactory.SetStringGE(Configuration.GetConnectionString("GrupoEmpresarialString")); services.AddDbContext <GrupoEmpresarialContext>(options => options.UseSqlServer(StringFactory.StringGE)); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Cuenta/Login/"; options.AccessDeniedPath = "/Cuenta/Login/"; }); services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN"); services.AddDistributedMemoryCache(); services.AddSession(options => { // Set a short timeout for easy testing. //options.IdleTimeout = TimeSpan.FromMinutes(30); options.Cookie.HttpOnly = true; // Make the session cookie essential options.Cookie.IsEssential = true; }); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.Configure <IISServerOptions>(options => { options.AutomaticAuthentication = false; }); }
public IActionResult ValidarGrupo(string grupo) { StringFactory.SetStringGE(HttpContext.Session, grupo); try { using (SqlConnection conn = new SqlConnection(StringFactory.StringGE)) { conn.Open(); conn.Close(); return(RedirectToAction("Login", "Cuenta")); } } catch (Exception ex) { AltivaLog.Log.Insertar(ex.ToString(), "Error"); return(RedirectToAction("Index", new { estado = "error" })); } }
public IActionResult Login(string grupo) { StringFactory.SetStringGE(grupo); try { using (SqlConnection conn = new SqlConnection(StringFactory.StringGE)) { conn.Open(); conn.Close(); return(RedirectToAction("Login", "Cuenta", new { grupo = grupo })); } } catch { return(RedirectToAction("Index", new { estado = "error" })); } }