-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathSecurityController.cs
36 lines (31 loc) · 1.16 KB
/
SecurityController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Synercoding.FormsAuthentication;
using System.Threading.Tasks;
namespace TestImplementation.ReadCookie.Controllers
{
[Authorize]
public class SecurityController : Controller
{
private readonly FormsAuthenticationOptions _formsAuthenticationOptions;
public SecurityController(IOptions<FormsAuthenticationOptions> options)
{
_formsAuthenticationOptions = options.Value;
}
public IActionResult Index()
{
var authCryptor = new FormsAuthenticationCryptor(_formsAuthenticationOptions);
var ticket = authCryptor.Unprotect(Request.Cookies["TestCookie"]);
ViewData["TestCookie-UserData"] = ticket.UserData;
return View();
}
public async Task<IActionResult> Logout()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectToAction(nameof(Index));
}
}
}