Example #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,
                              IWelcomeService welcomeService, ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage(); //开发环境,走这中间件,异常页面
            }
            else
            {
                app.UseExceptionHandler();
            }


            //app.UseMvc(builder =>
            //{
            //    builder.MapRoute("hello", "{controller=Home}/{action=Index}/{id?}");
            //});

            app.UseMvcWithDefaultRoute();


            //defaultfilesoptions options = new defaultfilesoptions();
            //options.defaultfilenames.clear();
            //options.defaultfilenames.add("zidingyi.html");    //修改
            //app.usedefaultfiles();
            //app.usestaticfiles();
            //app.UseFileServer();
            app.Use(next =>
            {
                logger.LogInformation("Use....");
                return(async HttpContext =>
                {
                    if (HttpContext.Request.Path.StartsWithSegments("/first"))
                    {
                        logger.LogInformation("first....");
                        await HttpContext.Response.WriteAsync("first!!!!!");
                    }
                    else
                    {
                        logger.LogInformation("HttpContext....");
                        await next(HttpContext);
                    }
                });
            });
            app.Run(async(context) =>
            {
                //var welcome = configuration["Welcome"];IConfiguration configuration,
                string welcome = welcomeService.GetMessage();
                logger.LogInformation("HttpContext....");
                await context.Response.WriteAsync(welcome);
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration configuration,
                              IWelcomeService welcomeService, ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.Use((next) =>
            {
                logger.LogInformation("App Use");
                return(async httpContext =>
                {
                    logger.LogInformation(" -----async HttpContext------");
                    if (httpContext.Request.Path.StartsWithSegments("/first"))
                    {
                        logger.LogInformation(" -----async First------");
                        await httpContext.Response.WriteAsync("First!");
                    }
                    else
                    {
                        logger.LogInformation(" -----async Others------");
                        await next(httpContext);
                    }
                });
            });
            //app.UseWelcomePage(new WelcomePageOptions()
            //{
            //	 Path = "/Welcome"
            //});
            app.UseStaticFiles();
            //启动默认的路由 例如:网站根路径 =》 HomeController/Index
            app.UseMvc(builder =>
            {
                // 约定路由
                builder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
                // 标签路由 在Controller中配置
            });

            app.Run(async(context) =>
            {
                //throw new Exception("No Exception");
                var message = welcomeService.GetMessage();
                await context.Response.WriteAsync(message);
            });
        }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            IWelcomeService welcomeService,
            ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }
            //服务器路径访问,文件访问中间件;
            app.UseFileServer();


            //MVC默认带路径;
            //app.UseMvcWithDefaultRoute();
            //MVC不带路径;
            app.UseMvc(builder =>
            {
                //home / Index-> HomeController Index()
                builder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
                // builder.MapRoute();
            });



            app.Run(async(context) =>
            {
                var welcome = welcomeService.GetMessage();
                await context.Response.WriteAsync(welcome);
            });
        }
Example #4
0
 public IActionResult WelcomeUS()
 {
     return(View((object)_usWelcomeService.GetMessage()));
 }
Example #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IWelcomeService welcomeService,
                              ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }


            //next:RequestDelegate 下一个中间件
            //app.Use(next =>
            //{
            //    logger.LogInformation("app.Use()...");
            //    return async httpContext =>
            //    {
            //        logger.LogInformation("----aysnc httpContext");
            //        if (httpContext.Request.Path.StartsWithSegments("/first"))
            //        {
            //            logger.LogInformation("---first");
            //            await httpContext.Response.WriteAsync("first");
            //        }
            //        else
            //        {
            //            logger.LogInformation("---next()");
            //            await next(httpContext);
            //        }
            //    };

            //});


            //app.UseDefaultFiles();
            app.UseStaticFiles();

            //app.UseFileServer();



            //app.UseWelcomePage(new WelcomePageOptions
            //{
            //    Path = "/welcome"

            //});


            app.UseMvc(bulider =>
            {
                bulider.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
            }
                       );


            //终端中间件
            app.Run(
                async(context) =>
            {
                var welcome = welcomeService.GetMessage();
                await context.Response.WriteAsync(welcome);
            }
                );
        }