This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Startup.cs
50 lines (43 loc) · 1.76 KB
/
Startup.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.DependencyInjection;
namespace RazorPagesWebSite
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => options.LoginPath = "/Login");
services.AddMvc()
.AddViewLocalization()
.AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizePage("/HelloWorldWithAuth");
options.Conventions.AuthorizeFolder("/Pages/Admin");
options.Conventions.AllowAnonymousToPage("/Pages/Admin/Login");
options.Conventions.AddPageRoute("/HelloWorldWithRoute", "Different-Route/{text}");
options.Conventions.AddPageRoute("/Pages/NotTheRoot", string.Empty);
})
.WithRazorPagesAtContentRoot();
}
public void Configure(IApplicationBuilder app)
{
app.UseAuthentication();
app.UseStaticFiles();
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
app.UseMvc();
}
}
}