.NET CORE2.0后台管理系统(一)配置API
2021-04-30 09:27
标签:es2017 2-2 关系 icon reac task wan pac sed 要写一个项目首先离不开的就是一个清晰的流程图,当然我这里很简单。 上诉完成后打开api下的Startup.cs文件,因为我是配置好了所在我直接上传代码然后介绍一下: 因为我采用了5个过滤器所以在上诉代码上addmvc中添加了5个过滤器。 上面的代码我都有注解,都很简单,欢迎学习交流。 .NET CORE2.0后台管理系统(一)配置API 标签:es2017 2-2 关系 icon reac task wan pac sed 原文地址:http://www.cnblogs.com/edna-lzh/p/7805349.html一:引用关系图
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyModel;
using System.Runtime.Loader;
using System.Reflection;
using KilyCore.Util.FilterGroup;
using KilyCore.Configure;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog.Web;
using KilyCore.Util.ApplicationService.DependencyIdentity;
namespace KilyCore.Api
{
public class Startup
{
public IEngine Engine { get; private set; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
GetAssembly();
GetConfiger();
Engine = EngineExtension.Context;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc(option =>
{
option.Filters.Add(typeof(AuthorizationFilter));
option.Filters.Add(typeof(ResourceFilter));
option.Filters.Add(typeof(ActionFilter));
option.Filters.Add(typeof(ExceptionFilter));
option.Filters.Add(typeof(ResultFilter));
option.RespectBrowserAcceptHeader = true;
});
//添加跨域
services.AddCors(option=>{
option.AddPolicy("KilyCore", builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
});
//添加Session
services.AddSession();
return Engine.ServiceProvider(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
{
//Nlog
logger.AddNLog();
env.ConfigureNLog("Nlog.config");
//设置全局跨域
app.UseCors("KilyCore");
//启用Session
app.UseSession();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
///
上一篇:用winrar和ftp命令实现自动备份文件并自动上传到指定的ftp服务器
下一篇:无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NET START命令启动它
文章标题:.NET CORE2.0后台管理系统(一)配置API
文章链接:http://soscw.com/index.php/essay/80347.html