Esempio n. 1
0
        /// <summary>
        /// Startup
        /// </summary>
        public Startup(IConfiguration configuration)
        {
            Configuration           = configuration;
            ApplicationData.AppName = "技术部任务系统";
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            string[] swaggerHelperXmlPathArray =
            {
                Path.Combine(basePath, "DevOA.WebAPI.xml"),
                Path.Combine(basePath, "Authority.DataTransmitModel.xml"),
                Path.Combine(basePath, "Authority.PresentationModel.xml")
            };
            _baseConfigure = new BaseConfigureServiceModel
            {
                AppName = ApplicationData.AppName,
                SwaggerHelperXmlPathArray = swaggerHelperXmlPathArray
            };
        }
Esempio n. 2
0
 public static void BaseConfigureServices(IServiceCollection services, BaseConfigureServiceModel baseConfigure)
 {
     #region 配置MVC
     services
     .AddMvc(options =>
     {
         //AuthorizationPolicy policy = ScopePolicy.Create(ApplicationConfig.IdentityServer.Scope);
         //options.Filters.Add(new AuthorizeFilter(policy));
         options.Filters.Add(typeof(ExceptionProcessFilter));
     })
     .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
     .AddJsonOptions(options =>
     {
         options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
         options.SerializerSettings.ContractResolver      = new DefaultContractResolver();
     });
     #endregion
     #region 配置Authentication
     //services.AddAuthentication("Bearer")
     //    .AddIdentityServerAuthentication(options =>
     //    {
     //        options.Authority = ApplicationConfig.IdentityServer.Url;
     //        options.RequireHttpsMetadata = false;
     //        options.ApiName = ApplicationConfig.IdentityServer.Scope;
     //        options.ApiSecret = ApplicationConfig.IdentityServer.Secret;
     //        options.EnableCaching = true;
     //        options.CacheDuration = TimeSpan.FromMinutes(10);
     //    });
     #endregion
     #region 帮助文档
     /*Swashbuckle.AspNetCore*/
     services.AddSwaggerGen(m =>
     {
         m.SwaggerDoc(baseConfigure.AppName, new Info
         {
             Version        = "0.1",
             Title          = baseConfigure.AppName,
             Description    = "提供WebAPI接口",
             TermsOfService = "None",
             Contact        = new Contact {
                 Name = "Materal", Email = "*****@*****.**", Url = ""
             }
         });
         m.AddSecurityDefinition("Bearer", new ApiKeyScheme
         {
             Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
             Name        = "Authorization",
             In          = "header",
             Type        = "apiKey"
         });
         m.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> >
         {
             { "Bearer", Enumerable.Empty <string>() }
         });
         foreach (string path in baseConfigure.SwaggerHelperXmlPathArray)
         {
             m.IncludeXmlComments(path);
         }
     });
     #endregion
     #region 跨域
     services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                                   .AllowAnyMethod()
                                                   .AllowAnyHeader()));
     #endregion
     //ServiceProvider provider = services.BuildServiceProvider();
     //AuthorityFilter.ServiceProvider = provider;
 }