Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void ConfigureServices(IServiceCollection services)
- {
- try
- {
- //services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
- services.AddAuthentication("CookieSecurityScheme")
- .AddCookie("CookieSecurityScheme", options =>
- {
- options.ExpireTimeSpan = new TimeSpan(90, 0, 0, 0);
- options.LoginPath = new PathString("/Home/Index/");
- options.AccessDeniedPath = new PathString("/Home/Index/");
- options.LogoutPath = new PathString("/Home/Index/");
- });
- services.AddMvc();
- services.AddAntiforgery();
- services.Configure<MvcOptions>(options =>
- {
- options.Filters.Add(new RequireHttpsAttribute());
- });
- }
- catch (Exception ex)
- {
- gFunc.ProcessError(ex);
- }
- }
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- try
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- app.UseBrowserLink();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- }
- app.UseStaticFiles();
- app.UseAuthentication();
- var options = new RewriteOptions().AddRedirectToHttps();
- app.UseRewriter(options);
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- routes.MapRoute(
- name: "signin",
- template: "{controller=Home}/{action=Index}/{agencyID}/{contactID}");
- });
- }
- catch (Exception ex)
- {
- gFunc.ProcessError(ex);
- }
- }
- // create claims
- var claims = new List<Claim>
- {
- new Claim(ClaimTypes.Name, c_signed_in.FirstName + gFunc.SPACE + c_signed_in.FamilyName),
- new Claim(ClaimTypes.Email, c_signed_in.Email),
- new Claim(ClaimTypes.SerialNumber, c_signed_in.AccountPassword)
- //new Claim(ClaimTypes.Email, c_signed_in.Email)
- };
- // create principal
- ClaimsPrincipal principal = new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));
- // sign-in
- await HttpContext.SignInAsync(scheme: "CookieSecurityScheme", principal: principal);
Add Comment
Please, Sign In to add comment