1 Star 0 Fork 0

siyisiyue/SpreadJsDemoApi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Startup.cs 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
siyisiyue 提交于 2021-03-10 16:10 . 添加项目文件。
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SpreadJsDemoApi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var conn = Configuration.GetConnectionString("Default");
//#region
services.AddCors(options =>
{
options.AddPolicy("any",
builder =>
{
builder.SetIsOriginAllowed(origin=>true).AllowAnyMethod().AllowAnyHeader().AllowCredentials() ;
});
});
//#endregion
services.AddDbContext<SpreadContext>(opt => opt.UseSqlServer(conn));
services.AddControllers();
services.AddAutoMapper(cfg =>
{ cfg.AddProfile<MapperConfig>(); });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("any");//
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/siyisiyue/spread-js-demo-api.git
[email protected]:siyisiyue/spread-js-demo-api.git
siyisiyue
spread-js-demo-api
SpreadJsDemoApi
master

搜索帮助