.NET CORE2.0后台管理系统(一)配置API
一:引用关系图
要写一个项目首先离不开的就是一个清晰的流程图,当然我这里很简单。

上诉完成后打开api下的Startup.cs文件,因为我是配置好了所在我直接上传代码然后介绍一下:
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();
}
/// <summary>
/// 加载所有程序集
/// </summary>
public void GetAssembly()
{
IList<Assembly> ass = new List<Assembly>();
var lib = DependencyContext.Default;
var libs = lib.CompileLibraries.Where(t => !t.Serviceable).Where(t => t.Type != "package").ToList();
foreach (var item in libs)
{
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(item.Name));
ass.Add(assembly);
}
Configer.Assembly = ass; }
/// <summary>
/// 获取连接字符串
/// </summary>
public void GetConfiger()
{
Configer.ConnentionString = Configuration.GetConnectionString("ConnectionString");
Configer.RedisConnectionString = Configuration["RedisConnectionString:host"];
Configer.ApiKey = Configuration["Key:ApiKey"];
}
}
}
因为我采用了5个过滤器所以在上诉代码上addmvc中添加了5个过滤器。
上面的代码我都有注解,都很简单,欢迎学习交流。
.NET CORE2.0后台管理系统(一)配置API的更多相关文章
- EntityFramework Core2.0 多对多关系配置
在EF6.0 中,多对多关系配置时,系统会自动生成第三张表,来将两张有互相约束关系的表联系起来,但是在EF Core2.0中,我们需要手动建立第三张表,比如说有两个模型Passage.cs和Cat ...
- 使用react全家桶制作博客后台管理系统 网站PWA升级 移动端常见问题处理 循序渐进学.Net Core Web Api开发系列【4】:前端访问WebApi [Abp 源码分析]四、模块配置 [Abp 源码分析]三、依赖注入
使用react全家桶制作博客后台管理系统 前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用react全家桶制作的博客后台管理系统 概述 该项目是基 ...
- 前后端分离后台管理系统 Gfast v3.0 全新发布
GFast V3.0 平台简介 基于全新Go Frame 2.0+Vue3+Element Plus开发的全栈前后端分离的管理系统 前端采用vue-next-admin .Vue.Element UI ...
- 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之七 || API项目整体搭建 6.2 轻量级ORM
更新 1.在使用的时候,特别是更新数据的时候,如果不知道哪里有问题,可以查看数据库 和 实体类 的字段,是否大小写一致,比如 name 和 Name 2.在使用Sqlsugar 的 CodeFirst ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(任务管理系统)-2项目搭建
系统要求 首先建议采用 Windows 10 专业版/企业版/教育版,且必须是64位操作系统,原因是docker装起来比较方便,Win7装起来比较麻烦,且不确定是否有其他问题(自己没有实践过) 其次W ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(1)-12基于cookie登录授权认证并实现前台会员、后台管理员同时登录
1.登录的实现 登录功能实现起来有哪些常用的方式,大家首先想到的肯定是cookie或session或cookie+session,当然还有其他模式,今天主要探讨一下在Asp.net core 2.0下 ...
- 基于vue2.0 +vuex+ element-ui后台管理系统:包括本地开发调试详细步骤
效果演示地址, github地址: demo演示: 1.About 此项目是 vue2.0 + element-ui + node+mongodb 构建的后台管理系统,所有的数据都是从 ...
- Net Core2.0 基于QuartzNet任务管理系统
Net Core2.0 基于QuartzNet任务管理系统 Quartz.NET官网地址:https://www.quartz-scheduler.net/ Quartz.NET文档地址:https: ...
- GO 前后端分离开源后台管理系统 Gfast v2.0.4 版发布
更新内容:1.适配插件商城,开发环境从后台直接安装插件功能:2.代码生成细节修复及功能完善(支持生成上传文件.图片及富文本编辑器功能):3.增加swagger接口文档生成:4.更新goframe版本至 ...
随机推荐
- 4.【nuxt起步】-具体练习一个h5实例
目标地址:https://www.vyuan8.com/vyuan/plugin.php?id=vyuan_fangchan&module=fangchan&pid=10079& ...
- HDOJ1071
The area 拿到题的第一想法,又是一道水题,知道P1.P2.P3三点的坐标,就能够确定抛物线的公式.确定抛物线的公式就能够进行积分,然后就没有然后了.纯粹的数学题. #include< ...
- JFinal学习 & Gradle配置续 & Tomcat配置
接上一篇对Gradle的学习,再用JFinal项目再建一个. 参考了这篇文章:https://my.oschina.net/u/1010578/blog/390094 但是其中没有代码,所以看了这篇 ...
- drag-html
<!doctype html><html><head><meta charset="UTF-8" /><title>Ca ...
- [Servlet&JSP] 从JSP到Servlet
JSP与Servlet是一体的两面,JSP最后都会被容器转译为Servlet源码,自己主动编译为.class文件,载入.class文件然后生成Servlet对象. 由容器转译后的Servlet类具有_ ...
- UVA - 1416 Warfare And Logistics (最短路)
Description The army of United Nations launched a new wave of air strikes on terroristforces. The ob ...
- PPAPI插件的动态创建、改动、删除
一旦你完毕了PPAPI插件的开发,实际使用时可能会有下列需求: 动态创建PPAPI插件 删除PPAPI插件 改变PPAPI插件的尺寸 实现起来非常easy,从JS里直接訪问DOM(BOM)就可以.以下 ...
- vue2 + typescript2 项目开发(环境配置)
Vue 引入 TypeScript vue init airyland/vux2 projectName 增加开发包的依赖 npm install typescript ts-loader --sav ...
- 建立第一个Sencha Touch应用
准备 开始开发前,请先到下面的地址下载Sencha Touch 2的包:http://www.sencha.com/products/touch/download/ .下载完解压后你会发现包里有很多文 ...
- 赵雅智_Android案例_刮刮乐
实现效果 主要代码 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...