Exemple #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, VNPTAPIContext VnptDbContext)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            // redirect to https
            //var options = new RewriteOptions().AddRedirectToHttps();
            // setup mvc

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                // Khai báo sử dụng exceptionhander, cần code  /home/error sau
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStaticFiles();
            // config swagger
            //setup mvc routes
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            //app.UseDefaultFiles();
            //app.UseMvcWithDefaultRoute();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            // tạo file swagger json
            app.UseSwagger(c =>
            {
                c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value);
            });

            // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
            // tạo page swagger helper từ swagger json
            app.UseSwaggerUI(c =>
            {
                //  url / description
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "VNPT API V1.0");
                c.RoutePrefix = "Helper";
            });
            //DbInitializer.Initialize(VnptDbContext);
        }
 public ProductController(VNPTAPIContext VnptDbContext)
 {
     VnptDB = VnptDbContext;
 }