-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
139 lines (112 loc) · 4.28 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
//using AspNet.Security.OAuth.Validation;
//using bVue.code.Providers;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using NLog.Web;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog;
using Microsoft.AspNetCore.HttpOverrides;
using System.Text;
//using TextTemplating.Infrastructure;
namespace WebApplication2Vue
{
public partial class Startup
{
public static IConfigurationRoot config { get; set; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
// if (env.IsDevelopment())
// {
// app.UseDeveloperExceptionPage();
// // app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
// // {
// // HotModuleReplacement = true
// // });
// }
// env.ConfigureNLog("nlog.config");
//add NLog to ASP.NET Core
// loggerFactory.AddNLog();
app.UseStatusCodePagesWithReExecute("/");
app.UseAuthentication();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseCors(x => x
.AllowAnyMethod()
.AllowAnyHeader()
.SetIsOriginAllowed(origin => true) // allow any origin
.AllowCredentials());
// app.UseSimpleTokenProvider(new TokenProviderOptions
// {
// Path = "/token",
// Audience = "ExampleAudience",
// Issuer = "ExampleIssuer",
// SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256),
// IdentityResolver = GetIdentity,
// Expiration = TimeSpan.FromHours(8)
// });
//GlobalConfiguration.Configure(WebApiConfig.Register);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{*path}");
});
}
SymmetricSecurityKey signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("secretKey"));
public static IServiceProvider DI;
public void ConfigureServices(IServiceCollection services)
{
//services.AddAuthentication(); //for isuing tokens
services.AddMvc(option => option.EnableEndpointRouting = false)
.AddJsonOptions(o =>
{
o.JsonSerializerOptions.PropertyNamingPolicy = null;
o.JsonSerializerOptions.DictionaryKeyPolicy = null;
});
services.AddMvcCore().AddApiExplorer();
services.AddCors();
// services.Configure<AuthorizationOptions>(options =>
// {
// options.AddPolicy("IAddComment", policy => policy.RequireClaim("IComment", "true"));
// });
//NLOG call this in case you need aspnet-user-authtype/aspnet-user-identity
//services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}
public static void RunSomeTasks()
{
//lite.RunDMC();
}
}//end startup
public static class Log
{
private static Logger _logger = LogManager.GetCurrentClassLogger();
public static void Debug(string message)
{
_logger.Debug(message);
}
public static void Error(string message)
{
_logger.Error(message);
}
public static void Warn(string message)
{
_logger.Warn(message);
}
}
}