1 Star 0 Fork 0

丁红信/WebTestC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Startup.cs 3.61 KB
一键复制 编辑 原始数据 按行查看 历史
dingdingc 提交于 2021-07-06 18:12 . TestNew
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
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.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using WebApp.Controllers;
namespace testweb
{
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)
{
//services.AddControllersWithViews();
services.AddControllers();
services.AddSwaggerGen((opt) =>
{
opt.SwaggerDoc("swaggerName", new OpenApiInfo()
{
Title = "swaggerInitialTest",//(必填)申请的标题。
Version = "5.3.1",//(必填)版本号(这里直接写的是Swashbuckle.AspNetCore包的版本号,(有写 v1 的))
Description = "Description",//对应用程序的简短描述。
Contact = new OpenApiContact()//公开API的联系信息
{
Email = "123456789@qq.com",
Name = "DC",
Extensions = null,
Url = null
},
License = new OpenApiLicense()//公开API的许可信息
{
Name = "ZhangSan",
Extensions = null,
Url = null
}
});
//添加中文注释
//拼接生成的XML文件路径
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
//HomeController为当前程序集下的一个类(可自定义一个当前应用程序集下的一个类)[用于获取程序集名称]
var commentsFileName = typeof(TestController).Assembly.GetName().Name + ".xml";
var xmlPath = Path.Combine(basePath, commentsFileName);
opt.IncludeXmlComments(xmlPath);
opt.DocInclusionPredicate((docName, description) => true);
});
}
// 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();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseSwagger();
app.UseSwaggerUI(opt =>
{
opt.SwaggerEndpoint("/swagger/swaggerName/swagger.json", "ProjectName");
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
//endpoints.MapControllerRoute(
// name: "default",
// pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/dhxghrep/web-test-c.git
git@gitee.com:dhxghrep/web-test-c.git
dhxghrep
web-test-c
WebTestC
master

搜索帮助