38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Security.Claims;
|
|
using Microsoft.AspNet.Builder;
|
|
using Microsoft.AspNet.Http;
|
|
using Microsoft.AspNet.Security.Cookies;
|
|
using Microsoft.Framework.DependencyInjection;
|
|
|
|
namespace CookieSample
|
|
{
|
|
public class Startup
|
|
{
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseServices(services =>
|
|
{
|
|
services.AddDataProtection();
|
|
});
|
|
|
|
app.UseCookieAuthentication(options =>
|
|
{
|
|
});
|
|
|
|
app.Run(async context =>
|
|
{
|
|
if (context.User == null || !context.User.Identity.IsAuthenticated)
|
|
{
|
|
context.Response.SignIn(new ClaimsIdentity(new[] { new Claim("name", "bob") }, CookieAuthenticationDefaults.AuthenticationType));
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
await context.Response.WriteAsync("Hello First timer");
|
|
return;
|
|
}
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
await context.Response.WriteAsync("Hello old timer");
|
|
});
|
|
}
|
|
}
|
|
} |