// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 15 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");//conventional routing }); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hosting Environment : " + env.EnvironmentName); }); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions(); developerExceptionPageOptions.SourceCodeLineCount = 10; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } app.UseHttpsRedirection(); //This line enables the app to use Swagger, with the configuration in the ConfigureServices method. // app.UseSwagger(); //This line enables Swagger UI, which provides us with a nice, simple UI with which we can view our API calls. //app.UseSwaggerUI(c => //{ // //c.SwaggerEndpoint("/swagger/v1/swagger.json","MyAPI"); // c.SwaggerEndpoint("/swagger/v1/swagger.json", $"v1"); // c.SwaggerEndpoint("/swagger/v2/swagger.json", $"v2"); //}); app.UseAuthentication(); app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions() { SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } app.UseStaticFiles(); //app.UseMvcWithDefaultRoute(); #region //Conventional Routing app.UseMvc(route => { route.MapRoute("default", "{controller=Home}/{action=Index}/{Id?}"); } ); #endregion app.Run(async(context) => { await context.Response.WriteAsync("Hello World!"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { DeveloperExceptionPageOptions pageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(pageOptions); //} //else { app.UseExceptionHandler("/Error"); //app.UseStatusCodePagesWithReExecute("/Error/{0}"); // app.UseStatusCodePagesWithRedirects("/Error/{0}"); } app.UseAuthentication(); app.UseStaticFiles(); app.UseHsts(); app.UseMvc(routes => { routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); //routes.MapRoute(name: "default", template: "sagar/{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; //一つ目のミドルウェア app.UseDeveloperExceptionPage(developerExceptionPageOptions); } else { app.UseExceptionHandler("/Error"); app.UseStatusCodePagesWithReExecute("/Error/{0}");//{0}には失敗したときのアクセスコードが自動的に入る。 } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { //Developer Handler Page With Option To Show 10 Line Of Code DeveloperExceptionPageOptions options = new DeveloperExceptionPageOptions(); options.SourceCodeLineCount = 10; app.UseDeveloperExceptionPage(options); } else { //Create Global Exceprion Handler app.UseExceptionHandler("/Home/Error"); } //Add Files Middleware app.UseStaticFiles(); //Add Authentication Middleware app.UseAuthentication(); //Add MVC Middleware app.UseMvc(routes => { routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions(); developerExceptionPageOptions.SourceCodeLineCount = 10; /* 錯誤頁面中出錯程式碼的顯示行數 */ app.UseDeveloperExceptionPage(developerExceptionPageOptions); } /* UseFileServer = UseDeafaultFiles + UseStaticFiles + UseDirectoryBrowser */ //FileServerOptions fileserveroptions = new FileServerOptions(); //fileserveroptions.DefaultFilesOptions.DefaultFileNames.Clear(); //fileserveroptions.DefaultFilesOptions.DefaultFileNames.Add("foo.html"); //app.UseFileServer(fileserveroptions); app.UseStaticFiles(); app.UseAuthentication(); //app.UseMvcWithDefaultRoute(); app.UseMvc(routing => { routing.MapRoute("Default", "{controller=home}/{action=index}/{id?}"); }); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); //await context.Response.WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName); }); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionOptions = new DeveloperExceptionPageOptions(); developerExceptionOptions.SourceCodeLineCount = 1; app.UseDeveloperExceptionPage(developerExceptionOptions); } else if (env.IsStaging() || env.IsProduction() || env.IsEnvironment("Custom")) { app.UseExceptionHandler("/Error"); app.UseStatusCodePagesWithReExecute("/Error/{0}"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvcWithDefaultRoute(); //app.Run(async (context) => //{ // //throw new Exception("Custom exception"); // await context.Response.WriteAsync("Employee Management Tool"); //}); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { 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(); } var options = new DeveloperExceptionPageOptions { SourceCodeLineCount = 2 }; app.UseDeveloperExceptionPage(options); //loggerFactory.AddLog4Net(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 5 }; app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseStatusCodePagesWithReExecute("/statuscode/{0}"); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // Inject logger to see how the pipleline works // These are middlewares. if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions() { // The number of lines for source code that will be displayed to show error SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } else { app.UseStatusCodePagesWithReExecute("/Error/"); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); //Authentication here app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsEnvironment("Development")) { DeveloperExceptionPageOptions options = new DeveloperExceptionPageOptions(); options.SourceCodeLineCount = 10; app.UseDeveloperExceptionPage(options); } //DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions(); //defaultFilesOptions.DefaultFileNames.Clear(); //defaultFilesOptions.DefaultFileNames.Add("foo.html"); // app.UseRouting(); //app.UseDefaultFiles(defaultFilesOptions); //MvcOptions mvcOptions = new MvcOptions(); //mvcOptions.EnableEndpointRouting = false; app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); //app.Use(async (context, next) => // { // await context.Response.WriteAsync("Middleware1 begins"); // await next.Invoke(); // await context.Response.WriteAsync("Middleware1 ends"); // } //); //app.Use(async (context,next) => //{ // await context.Response.WriteAsync("Middleware2 begins"); // await context.Response.WriteAsync("Middleware2 ends"); //} //); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions d = new DeveloperExceptionPageOptions { SourceCodeLineCount = 2 }; app.UseDeveloperExceptionPage(d); } else if (env.IsProduction() || env.IsStaging()) { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); //app.UseMvcWithDefaultRoute(); app.UseMvc(); //app.UseMvc(routes => //{ Rutas personalizadas // routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); //}); //app.Run( async (context) => //{ // await context.Response.WriteAsync("Hola"); //}); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions dEPO = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(dEPO); } //app.UseFileServer(); app.UseStaticFiles(); app.UseRouting(); //app.UseMvcWithDefaultRoute(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller}/{action}/{id?}"); // endpoints.MapGet("/", async context => // { // await context.Response.WriteAsync("Hello World!" + env.EnvironmentName); // //await context.Response.WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName); // //await context.Response.WriteAsync(_config["mykey"]); // }); }); app.Run(async(context) => { await context.Response.WriteAsync("Hello World"); }); }
public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env) { //use cookie authentication app.UseAuthentication(); //use session app.UseSession(); //handle static files var provider = new FileExtensionContentTypeProvider(); // Add new mappings provider.Mappings[".svg"] = "image/svg"; var options = new StaticFileOptions { ContentTypeProvider = provider }; app.UseStaticFiles(options); //exception handling var errOptions = new DeveloperExceptionPageOptions(); errOptions.SourceCodeLineCount = 10; app.UseDeveloperExceptionPage(); //server if finished configuring Configured(app, env, config); //run Datasilk application app.Run(async(context) => { Run(context); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger <Startup> logger) { // 数据初始化 app.UseDataInitializer(); if (env.IsDevelopment()) { DeveloperExceptionPageOptions options = new DeveloperExceptionPageOptions { SourceCodeLineCount = 3 }; app.UseDeveloperExceptionPage(options); } else if (env.IsStaging() || env.IsProduction() || env.IsEnvironment("UAT")) { // 显示用户友好的错误页面 app.UseExceptionHandler("/Error"); app.UseStatusCodePagesWithReExecute("/Error/{0}"); } app.UseStaticFiles(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "MockSchoolManagement API V1"); }); app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(ep => { ep.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions doptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 2 }; app.UseDeveloperExceptionPage(doptions); } else { app.UseExceptionHandler("/Error"); //app.UseStatusCodePages("/Error/{0}"); //app.UseStatusCodePagesWithRedirects("/Error/{0}"); app.UseStatusCodePagesWithReExecute("/Error/{0}"); } //else if (env.IsStaging() || env.IsProduction() || env.IsEnvironment("UAT")) //{ // app.UseExceptionHandler("/Error"); //} app.UseStaticFiles(); //app.UseMvc(); // app.UseMvcWithDefaultRoute(); app.UseMvc(routes => { // routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions d = new DeveloperExceptionPageOptions() { SourceCodeLineCount = 2 }; app.UseDeveloperExceptionPage(d); } else if (env.IsProduction() || env.IsStaging()) { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseCors(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}"); }); app.Run(async(context) => { await context.Response.WriteAsync("Texto"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { var options = new DeveloperExceptionPageOptions { SourceCodeLineCount = 2 }; app.UseDeveloperExceptionPage(options); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { // developer exception - you can adjust number of lines before and after the exception DeveloperExceptionPageOptions pageOptions = new DeveloperExceptionPageOptions(); pageOptions.SourceCodeLineCount = 4; app.UseDeveloperExceptionPage(pageOptions); } else { app.UseExceptionHandler("/Home/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.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(); } ; //FileServerOptions fileServerOptions = new FileServerOptions(); //fileServerOptions.DefaultFilesOptions.DefaultFileNames.Clear(); //fileServerOptions.DefaultFilesOptions.DefaultFileNames.Add("foo.html"); //app.UseFileServer(fileServerOptions); //app.UseDefaultFiles(); //app.UseStaticFiles(); app.UseFileServer(); app.UseRouting(); app.Run(async(context) => { throw new Exception("Some Erro Processing the request"); await context.Response .WriteAsync("helloooo"); }); //app.UseEndpoints(endpoints => //{ // endpoints.MapGet("/", async context => // { // await context.Response // .WriteAsync("hello"); // }); //}); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 5 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } else { app.UseExceptionHandler("/Error"); } //app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); app.Run(async(context) => { logger.LogInformation("MV1 : Incoming request"); await context.Response.WriteAsync("Hello World!"); await context.Response.WriteAsync(_config["Mykey"]); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { //设置引发异常代码的上下文行数 SourceCodeLineCount = 5 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } //否则显示用户友好的错误页面 else if (env.IsStaging() || env.IsProduction() || env.IsEnvironment("UAT")) { app.UseExceptionHandler("/Error"); } app.UseFileServer(); app.Run(async(context) => { throw new Exception("这是一个测试的异常页面"); await context.Response.WriteAsync("Hello world"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //开发者异常页面中间件用于开发环境下使用,快速定位错误信息,需注册在前 if (env.IsDevelopment()) { //对异常页进行配置 DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { //设置报错代码行数 SourceCodeLineCount = 25 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } /* * //对默认文件中间件的默认文件做配置 * DefaultFilesOptions defaultFiles = new DefaultFilesOptions(); * defaultFiles.DefaultFileNames.Clear(); * defaultFiles.DefaultFileNames.Add("52abp.com.html"); * * //添加默认文件中间件,可打开非wwwroot文件夹的文件,该中间件必须注册在UseStaticFiles中间件之前,否则无法生效 * app.UseDefaultFiles(defaultFiles);*/ //添加静态文件中间件,用于打开wwwroot文件夹中的文件 app.UseStaticFiles(); /* //添加文件服务中间件,一般不推荐使用,该中间件会使项目文件目录暴露在公网之下 * app.UseFileServer();*/ //使用默认路由 //app.UseMvcWithDefaultRoute(); //使用自定义路由,通过模板映射规则寻找URL app.UseMvc(routes => routes.MapRoute("default", "{controller}/{action}/{id?}")); /*更自由的路由方式,属性路由,只开启MVC服务,路由规则到控制器下配置,该方式可以完全自定义URL而不必按照{controller}/{action}/{id} * 模板定义路由规则,但其弊端是每个自定义的URL都需要到具体方法下配置,且被属性路由修饰过的方法会覆盖常规路由,可和常规自定义路由结合使用*/ //app.UseMvc(); /* app.Run(async (context) => * { * await context.Response.WriteAsync(_configuration.GetConnectionString("StudentDBConnection")); * }); */ /* app.UseEndpoints(endpoints => * { * endpoints.MapGet("/", async context => * { * //var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; * //var configureValue = _configuration["MyKey"]; * await context.Response.WriteAsync(_configuration.GetConnectionString("StudentDBConnection")); * }); * });*/ }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions() { SourceCodeLineCount = 25 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } else { /* app.UseStatusCodePagesWithRedirects("/Error/{0}");*/ //This will Redirect to Error Controller app.UseExceptionHandler("/Error"); app.UseStatusCodePagesWithReExecute("/Error/{0}"); } FileServerOptions defaultFiles = new FileServerOptions(); defaultFiles.DefaultFilesOptions.DefaultFileNames.Clear(); defaultFiles.DefaultFilesOptions.DefaultFileNames.Add("fo.html"); //app.UseDefaultFiles(); app.UseStaticFiles(); //app.UseFileServer(defaultFiles); //app.UseMvcWithDefaultRoute(); app.UseMvc(route => { route.MapRoute( name: "default", template: "{controller=Home}/{action=ShowAllEmployee}/{id?}" ); }); // app.UseFileServer(); //app.Run(async (context) => //{ // //await context.Response.WriteAsync("Hello World!"); // // throw new Exception("Some thing is Wrong Pleae Try Again "); // //await context.Response.WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName); // logger.LogInformation("Message before the Envirenemt verable calling"); // await context.Response.WriteAsync(_config["MyKey"]); // logger.LogInformation("Message after the Envirenemt verable calling"); //}); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions options = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; // app.UseExceptionHandler("/error-local-development"); app.UseDeveloperExceptionPage(options); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "EndPointsWebAPINetCore v1"); c.SwaggerEndpoint("/swagger/v2/swagger.json", "EndPointsWebAPINetCore v2"); }); } else if (env.IsStaging() || env.IsEnvironment("UAT") || env.IsProduction()) { app.UseExceptionHandler("/error"); //unhandled Errors // app.UseStatusCodePagesWithReExecute("/Error/{0}"); for Mvc for errorcode } app.UseHttpsRedirection(); app.UseFileServer(); // app.UseStaticFiles(); app.UseDefaultFiles app.UseRouting(); app.UseAuthentication(); //app.Use(async (Context, next) => //{ // if (Context.Request.Headers.Keys.Contains("Authorized")) // { // logger.LogInformation(Context.Request.Body.Length.ToString()); // await next(); // logger.LogInformation(Context.Response.Body.Length.ToString()); // } //}); //app.Use(async (Context, next) => //{ // if (Context.Request.Headers.Keys.Contains("Authorized")) // { // await next(); // } //}); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { // customize dev exception page DeveloperExceptionPageOptions devExOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(devExOptions); } else { app.UseExceptionHandler("/Error"); // app.UseStatusCodePagesWithRedirects("/Error/{0}"); // Redirects to the error handling page. Changes address bar. Returns status 200 eventually to browser. app.UseStatusCodePagesWithReExecute("/Error/{0}"); // No redirects. Preserves original url (including query strings). Returns 404 eventually. } #region customize default html page method 1 //// customize default html page //DefaultFilesOptions dfOptions = new DefaultFilesOptions(); //dfOptions.DefaultFileNames.Clear(); //dfOptions.DefaultFileNames.Add("fancy.html"); //// order of these two 'use's is very important //// UseDefaultFiles() must present ahead of UseStaticFiles() //app.UseDefaultFiles(options); //app.UseStaticFiles(); #endregion #region customize default html page method 2 //FileServerOptions fsOptions = new FileServerOptions(); //fsOptions.DefaultFilesOptions.DefaultFileNames.Clear(); //fsOptions.DefaultFilesOptions.DefaultFileNames.Add("fancy.html"); //app.UseFileServer(fsOptions); #endregion app.UseFileServer(); app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions() { //used to customize DeveloperExceptionPage SourceCodeLineCount = 1 };//newly added //DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions(); //developerExceptionPageOptions.SourceCodeLineCount = 1; app.UseDeveloperExceptionPage(developerExceptionPageOptions); //app.UseDeveloperExceptionPage(); origin app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/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.Run(async (context) => // { // // throw new Exception("Error Process is going around"); // await context.Response.WriteAsync("Hello Environment: " + env.EnvironmentName); // await context.Response.WriteAsync(System.Diagnostics. // Process.GetCurrentProcess().ProcessName); // }); //app.UseMvc(routes => //{ // //routes.MapRoute("default", "{controller}/{action}/{id}"); // routes.MapRoute( // name: "default", // template: "{controller=Home}/{action=Index}/{id?}"); //}); app.UseSession(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "areas", template: "{area=Customers}/{controller=Home}/{action=Index}/{id?}" ); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } else { app.UseExceptionHandler("/Error"); app.UseStatusCodePagesWithReExecute("/Error/{0}"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseRouting(); // logger.LogInformation("Before Use MVC."); // app.UseMvcWithDefaultRoute(); // logger.LogInformation("After Use MVC."); // app.Use(async (context, next) => // { // logger.LogInformation("MW1: Incoming Request"); // await next.Invoke(); // logger.LogInformation("MW1: Outgoing Response"); // }); // app.Use(async (context, next) => // { // logger.LogInformation("MW2: Incoming Request"); // await next.Invoke(); // logger.LogInformation("MW2: Outgoing Response"); // }); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("Default", "{controller=Home}/{action=Index}/{id?}"); }); //app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger <Startup> logger) { if (env.IsDevelopment()) { DeveloperExceptionPageOptions developerExceptionPageOptions = new DeveloperExceptionPageOptions { SourceCodeLineCount = 10 }; app.UseDeveloperExceptionPage(developerExceptionPageOptions); } // app.Use(async (context, next) => // { // logger.LogInformation("MW1: Incoming Request"); // await next(); // logger.LogInformation("MW1: Outgoing Response"); // }); // app.Use(async (context, next) => // { // logger.LogInformation("MW2: Incoming Request"); // await next(); // logger.LogInformation("MW2: Outgoing Response"); // }); DefaultFilesOptions defaultfileoptions = new DefaultFilesOptions(); // Clear default file names and add foo.html as default name defaultfileoptions.DefaultFileNames.Clear(); defaultfileoptions.DefaultFileNames.Add("foo.html"); // default file name should be index.html/htm, default.html/htm // app.UseDefaultFiles(); app.UseDefaultFiles(defaultfileoptions); // UseDefaultFiles should be before UseStaticFiles app.UseStaticFiles(); // FileServerOptions fileserveroptions = new FileServerOptions(); // // Clear default file names and add foo.html as default name // fileserveroptions.DefaultFilesOptions.DefaultFileNames.Clear(); // fileserveroptions.DefaultFilesOptions.DefaultFileNames.Add("foo.html"); // app.UseFileServer(fileserveroptions); // // Combination of UseDefaultFiles, UseStaticFiles and UseDirectoryBrowser app.Run(async(context) => { // throw new Exception("Some error processing request"); await context.Response.WriteAsync(_config["myval"] + env.EnvironmentName); logger.LogInformation("MW3: Request handled and response produced"); }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //load application-wide memory store Server server = new Server(); //use session app.UseSession(); //handle static files var options = new StaticFileOptions {ContentTypeProvider = new FileExtensionContentTypeProvider()}; app.UseStaticFiles(options); //exception handling var errOptions = new DeveloperExceptionPageOptions(); errOptions.SourceCodeLineCount = 10; app.UseDeveloperExceptionPage(); //get server info from config.json checkForConfig(); var config = new ConfigurationBuilder() .AddJsonFile(server.MapPath("config.json")) .AddEnvironmentVariables().Build(); server.sqlActive = config.GetSection("Data:Active").Value; server.sqlConnection = config.GetSection("Data:" + server.sqlActive).Value; server.https = config.GetSection("https").Value.ToLower() == "true" ? true : false; var isdev = false; switch (config.GetSection("Environment").Value) { case "development": case "dev": server.environment = Server.enumEnvironment.development; isdev = true; break; case "staging": case "stage": server.environment = Server.enumEnvironment.staging; break; case "production": case "prod": server.environment = Server.enumEnvironment.production; break; } //configure server security server.bcrypt_workfactor = int.Parse(config.GetSection("Encryption:bcrypt_work_factor").Value); server.CheckAdminPassword(); //run Websilk application app.Run(async (context) => { var requestStart = DateTime.Now; DateTime requestEnd; TimeSpan tspan; var requestType = ""; var path = cleanPath(context.Request.Path.ToString()); var paths = path.Split('/').Skip(1).ToArray(); var extension = ""; //get request file extension (if exists) if(path.IndexOf(".")>= 0) { for (int x = path.Length - 1; x >= 0; x += -1) { if (path.Substring(x, 1) == ".") { extension = path.Substring(x + 1); return; } } } server.requestCount += 1; if (isdev) { Console.WriteLine("--------------------------------------------"); Console.WriteLine("{0} GET {1}", DateTime.Now.ToString("hh:mm:ss"), context.Request.Path); } if (paths.Length > 1) { if(paths[0]=="api") { //run a web service via ajax (e.g. /api/namespace/class/function) IFormCollection form = null; if(context.Request.ContentType != null) { if (context.Request.ContentType.IndexOf("application/x-www-form-urlencoded") >= 0) { }else if (context.Request.ContentType.IndexOf("multipart/form-data") >= 0) { //get files collection from form data form = await context.Request.ReadFormAsync(); } } if (cleanNamespace(paths)) { //execute web service var ws = new Pipeline.WebService(server, context, paths, form); requestType = "service"; } } } if(requestType == "" && extension == "") { //initial page request var r = new Pipeline.PageRequest(server, context); requestType = "page"; } if (isdev) { requestEnd = DateTime.Now; tspan = requestEnd - requestStart; server.requestTime += (tspan.Seconds); Console.WriteLine("END GET {0} {1} ms {2}", context.Request.Path, tspan.Milliseconds, requestType); Console.WriteLine(""); } }); }