Guest User

Untitled

a guest
Jan 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. try
  4. {
  5. //services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
  6. services.AddAuthentication("CookieSecurityScheme")
  7. .AddCookie("CookieSecurityScheme", options =>
  8. {
  9. options.ExpireTimeSpan = new TimeSpan(90, 0, 0, 0);
  10. options.LoginPath = new PathString("/Home/Index/");
  11. options.AccessDeniedPath = new PathString("/Home/Index/");
  12. options.LogoutPath = new PathString("/Home/Index/");
  13. });
  14.  
  15. services.AddMvc();
  16. services.AddAntiforgery();
  17. services.Configure<MvcOptions>(options =>
  18. {
  19. options.Filters.Add(new RequireHttpsAttribute());
  20. });
  21. }
  22. catch (Exception ex)
  23. {
  24. gFunc.ProcessError(ex);
  25. }
  26. }
  27.  
  28. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  29. {
  30. try
  31. {
  32. if (env.IsDevelopment())
  33. {
  34. app.UseDeveloperExceptionPage();
  35. app.UseBrowserLink();
  36. }
  37. else
  38. {
  39. app.UseExceptionHandler("/Home/Error");
  40. }
  41. app.UseStaticFiles();
  42. app.UseAuthentication();
  43.  
  44. var options = new RewriteOptions().AddRedirectToHttps();
  45. app.UseRewriter(options);
  46.  
  47. app.UseMvc(routes =>
  48. {
  49. routes.MapRoute(
  50. name: "default",
  51. template: "{controller=Home}/{action=Index}/{id?}");
  52.  
  53. routes.MapRoute(
  54. name: "signin",
  55. template: "{controller=Home}/{action=Index}/{agencyID}/{contactID}");
  56. });
  57. }
  58. catch (Exception ex)
  59. {
  60. gFunc.ProcessError(ex);
  61. }
  62. }
  63.  
  64. // create claims
  65. var claims = new List<Claim>
  66. {
  67. new Claim(ClaimTypes.Name, c_signed_in.FirstName + gFunc.SPACE + c_signed_in.FamilyName),
  68. new Claim(ClaimTypes.Email, c_signed_in.Email),
  69. new Claim(ClaimTypes.SerialNumber, c_signed_in.AccountPassword)
  70. //new Claim(ClaimTypes.Email, c_signed_in.Email)
  71. };
  72.  
  73. // create principal
  74. ClaimsPrincipal principal = new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));
  75.  
  76. // sign-in
  77. await HttpContext.SignInAsync(scheme: "CookieSecurityScheme", principal: principal);
Add Comment
Please, Sign In to add comment