码迷,mamicode.com
首页 > 数据库 > 详细

NetCore WebApi 应用事项,验证,授权,数据库Orm(EFCore、XPO等)

时间:2019-08-24 20:17:25      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:path   ica   option   inf   rect   nbsp   app   on()   contex   

1、首先参考:我的第一个netcore2.2 api项目搭建(一)   https://www.cnblogs.com/sy-ds/p/10832504.html

      启用身份验证 Startup 中增加     app.UseAuthentication();

 

 

 

二、使用 Swagger 的过程:

1、nuget搜索:Swashbuckle.AspNetCore,安装 Swagger 工具 Nuget包。

2、在startup 的 ConfigureServices  注册swagger

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info
                {
                    //Version = "v1",
                    Title = "MyFirst API",//" API",
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                options.IncludeXmlComments(xmlPath, true);
                xmlPath = Path.Combine(AppContext.BaseDirectory, "JH.OPEMR.Model.xml");
                options.IncludeXmlComments(xmlPath, true);
            });
3、在Configure中启用swagger
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

 



NetCore WebApi 应用事项,验证,授权,数据库Orm(EFCore、XPO等)

标签:path   ica   option   inf   rect   nbsp   app   on()   contex   

原文地址:https://www.cnblogs.com/hopesun/p/11405726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!