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 welcomeServie,
            ILogger <Startup> logger
            )
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();//非开发
            }
            //app.Use(next =>
            //{
            //    logger.LogInformation("app.Use().............");
            //    return async HttpContext =>
            //    {
            //        if (HttpContext.Request.Path.StartsWithSegments("/first"))
            //        {
            //            logger.LogInformation(".............first");
            //            await HttpContext.Response.WriteAsync("First!!");
            //        }
            //        else {
            //            logger.LogInformation(".............next(HttpContext)");
            //            await next(HttpContext);
            //        }
            //    };
            //});

            //app.UseWelcomePage(new WelcomePageOptions {
            //    Path = "/welcome"
            //});
            //app.UseDefaultFiles();//打开默认首页
            app.UseStaticFiles();//静态文件伺服
            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath  = "/node_modules",
                FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "node_modules"))
            });

            //app.UseFileServer();//包含上面两个

            app.UseAuthentication();

            app.UseMvcWithDefaultRoute();



            //
            //app.Run(async (context) =>
            //{
            //    var welcome = welcomeServie.getMessage();
            //    await context.Response.WriteAsync(welcome);
            //});
        }
Example #2
0
 public UpdateController(
     ITelegramBotClient telegramBot,
     ILogger <UpdateController> logger,
     IWelcomeService welcomeService)
 {
     _telegramBot    = telegramBot;
     _logger         = logger;
     _welcomeService = welcomeService;
 }
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)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     app.UseAuthentication();
     app.UseMvc(route =>
     {
         route.MapRoute(name: "default", template: "{controller=home}/{action=index}/{id?}");
     });
 }
Example #4
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 #5
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 #6
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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //非开发环境下使用
                app.UseExceptionHandler();
            }

            // 显示index.html的中间件
            // app.UseDefaultFiles();
            app.UseStaticFiles();
            // app.UseFileServer();
            //UseFileServer包含前两个中间件UseDefaultFiles和UseStaticFiles
            // 使用默认路由的MVC框架
            // app.UseMvcWithDefaultRoute(); //源代码 "{controller=Home}/{action=Index}/{id?}"
            //自定义路由
            app.UseMvc(builder =>
            {
                // /Home/Index/3
                builder.MapRoute("Default", "{controller}/{action}/{id?}");// ?表示可选 按照约定配置路由
            });
            app.UseRouting();
            //判断是否为单元测试环境
            // env.EnvironmentName = "UnionTest";
            // env.IsEnvironment("UnionTest");
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    var welcome = welcomeService.getMessage();
                    await context.Response.WriteAsync(welcome);
                });
            });
        }
Example #7
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 #8
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger, IWelcomeService welcomeService)
 {
     _logger         = logger;
     _welcomeService = welcomeService;
 }
 public override void SetRepositories()
 {
     _Service = new WelcomeService((U, P, C, A) =>
                                   ExecuteQueryWithReturnTypeAndNetworkAccessAsync <WelcomeResponse>(U, P, C, A));
     _Reposetory = new WelcomeRepository(_MasterRepo, _Service);
 }
 public HomeController(IWelcomeService welcomeService)
 {
     _welcomeService = welcomeService;
 }
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log, IWelcomeService welcomeService)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            return(welcomeService != null
                ? (ActionResult) new OkObjectResult($"Hello, {welcomeService.WelcomeMessage()}")
                : new BadRequestObjectResult("WelcomeService not resolved"));
        }
Example #12
0
 public WelcomeFunctions(IWelcomeService welcomeService)
 {
     _welcomeService = welcomeService;
 }
Example #13
0
 public HomeController(IServiceProvider serviceProvider)
 {
     _usWelcomeService = serviceProvider.GetService <WelcomeServiceUS>();
     _idWelcomeService = serviceProvider.GetService <WelcomeServiceID>();
 }
Example #14
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);
            }
                );
        }
 public WelcomeRepository(IMasterRepository masterRepository, IWelcomeService service)
     : base(masterRepository)
 {
     _Service = service;
 }
Example #16
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

            )
        {
            //服务注册和管道
            var welcome = configuration["Welcome"];

            Console.WriteLine(welcome);
            var ws = welcomeService.getMessage();

            Console.WriteLine(ws);

            //app.UseWelcomePage();
            #region 中间件使用
            //app.Use(next =>
            //{
            //    return async httpContext =>
            //    {
            //        if (httpContext.Request.Path.StartsWithSegments("/first"))
            //        {
            //            await httpContext.Response.WriteAsync("First!!!");
            //        }
            //        else
            //        {
            //            logger.LogInformation("---next(xxxx)----");
            //            await next(httpContext);
            //        }
            //    };
            //});
            //app.UseWelcomePage(new WelcomePageOptions { Path="/welcome"});
            #endregion



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

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/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.UseCookiePolicy();

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