Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");

            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });

            app.UseAuthentication();

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseFileServer();
        }
Ejemplo n.º 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,
                              FeatureToggles features
                              )
        {
            app.UseExceptionHandler("/error.html");


            //if (configuration.GetValue<bool>("FeatureToggles:EnableDeveloperException"))
            if (features.EnableDeveloperException)
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error");
                }
                await next();
            });
            //else
            //{
            //    app.UseExceptionHandler("/Error");
            //}

            //app.UseStaticFiles();

            //app.UseMvc();
            app.UseFileServer();
        }
Ejemplo n.º 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,
            ILoggerFactory loggerFactory,
            FeatureToggles features
            )
        {
            loggerFactory.AddConsole();

            app.UseExceptionHandler("/error.html");

            if (features.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });

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

            app.UseFileServer();
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            FeatureToggles features
            )
        {
            app.UseExceptionHandler("/error.html");
            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR");
                }

                await next();
            });

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

            app.UseFileServer();
        }
Ejemplo n.º 5
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");

            // configuration.GetValue<bool>("FeatureToggles:EnableDeveloperExceptions")
            if (features.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error!");
                }

                await next();
            });

            app.UseIdentity();

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

            app.UseFileServer();
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");

            if (features.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error!");
                }

                await next();
            });

            // egen middleware - udkommenteret da den siger at localhost ikke må få adgang med en HTTP401
            //app.UseMiddleware<ExcludeLocalhostMiddleware>();

            app.UseFileServer();

            app.UseIdentity();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id:int?}");
            });
        }
Ejemplo n.º 7
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FeatureToggles features)
        {
            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error.html");
            }
            app.Use(async(ctx, next) =>
            {
                if (ctx.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Woah!");
                }
                await next();
            });

            app.UseFileServer();
            app.UseCookiePolicy();
            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default",
                                "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");

            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });


            app.UseFileServer();
        }
Ejemplo n.º 9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env
                              ,
                              FeatureToggles feature)
        {
            app.UseExceptionHandler("/error.html");
            /// this will only work with production pages soo go on properties then debug
            /// and change envi. var value to production
            ///

            /* if (configuration.GetValue<bool>("FeatureToggles:DeveloperExceptions"))
             * {
             *   app.UseDeveloperExceptionPage();
             * }*/
            if (feature.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }



            app.UseRouting();

            /*
             * app.UseEndpoints(endpoints =>
             * {
             *  endpoints.MapGet("/hellow", async context =>
             *  {
             *      await context.Response.WriteAsync("Hello World! It's N1ki Brahmbhatt");
             *  });
             *  endpoints.MapGet("/", async context =>
             *  {
             *      await context.Response.WriteAsync("Hello World! It's Vishal Brahmbhatt");
             *  });
             * });*/



            /// for error handling checking

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error!");
                }

                await next();
            });///instead of use this use this one---> down

            app.UseAuthentication();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(name: "default",
                                             pattern: "{controller=Home}/{action=Index}/{id?}");
            });
            app.UseFileServer(); //for directly use of wwwroot folder. . .
        }
Ejemplo n.º 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");

            //if (env.IsDevelopment())
            //if (configuration["EnableDeveloperExceptions"] == "True")
            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }


            //app.UseRouting();

            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapGet("/", async context =>
            //    {
            //        await context.Response.WriteAsync("Hello Rudresh!");
            //    });
            //});

            //app.Use(async (context, next) => {
            //    await context.Response.WriteAsync("Hello Rudresh Use! ");
            //    await next();
            //});

            app.UseFileServer();
            //app.UseStaticFiles();


            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR");
                }
                await next();
            });

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

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello Rudresh Run!");
            });
        }
Ejemplo n.º 11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");
            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });

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

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("Default", "{controller=Home}/{action=Index}/{id?}");
                //endpoints.MapControllers();
                //endpoints.MapGet("/", async context =>
                //{
                //    await context.Response.WriteAsync("Hello California!");
                //});
                //endpoints.MapGet("/weather", async context =>
                //{
                //    await context.Response.WriteAsync("Its sunny!");
                //});
                //endpoints.MapFallback(async context =>
                //{
                //    await context.Response.WriteAsync("Fallback to home!");
                //});
            });

            app.UseFileServer();
        }
Ejemplo n.º 12
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,
                              FeatureToggles features
                              )
        {
            app.UseExceptionHandler("/error.html");

            //var configuration = new ConfigurationBuilder()
            //                        .AddEnvironmentVariables()
            //                        .AddJsonFile(env.ContentRootPath + "/config.json")
            //                        .AddJsonFile(env.ContentRootPath + "/config.development.json", true) // Optional file
            //                        .Build();

            //if (env.IsDevelopment())
            //if (configuration["EnableDeveloperExceptions"] == "True")
            //if (configuration.GetValue<bool>("FeatureToggles:EnableDeveloperExceptions"))
            if (features.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            app.UseIdentity();

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

            app.UseFileServer();
        }
Ejemplo n.º 13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            FeatureToggles features)
        {
            app.UseExceptionHandler("/error.html");

            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) => {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new System.Exception("ERROR!");
                }
                await next();
            });

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

            app.UseFileServer();

            /*
             * app.UseRouting();
             *
             * app.UseEndpoints(endpoints =>
             * {
             *  endpoints.MapGet("/", async context =>
             *  {
             *      await context.Response.WriteAsync("Hello ASP.NET Core!");
             *  });
             * });
             */
        }
Ejemplo n.º 14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, FeatureToggles feature)
        {
            //app.UseExceptionHandler("/error.html");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/error.html");
            }

            //if (feature.EnableDeveloperExceptions)
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error");
                }
                await next();
            });

            app.UseIdentity();

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

            app.UseFileServer();
        }
Ejemplo n.º 15
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, FeatureToggles features)
        {
            loggerFactory.AddConsole();

            app.UseExceptionHandler("/error.html");


            #region Depricated - Use Injected FeaturesToggle
            //if (configuration.GetValue<bool>("FeatureToggles:EnableDeveloperExceptions"))
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            #endregion

            if (features.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(AppContext, next) =>
            {
                if (AppContext.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error2!");
                }
                await next();
            });

            app.UseIdentity();

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

            app.UseFileServer();
        }
Ejemplo n.º 16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            FeatureToggles featureToggles)
        {
            app.UseExceptionHandler("/error.html");
            //configuration.GetValue<bool>("FeatureToggles:DeveloperExceptions")

            //if (featureToggles.DeveloperExceptions)
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });


            // app.UseFileServer();
            app.UseStaticFiles();
            // app.UseMvcWithDefaultRoute();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();
            });

            app.UseEndpoints(endpoints =>
            {
                //endpoints.MapRazorPages();
                endpoints.MapControllerRoute(
                    name: "areaRoute",
                    pattern: "{area:exists}/{controller}/{action}",
                    defaults: new { action = "Index" });

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                endpoints.MapControllerRoute(
                    name: "api",
                    pattern: "{controller}/{id?}");
            });

            ////configuration["EnableDeveloperExceptions"] == "True"; // custom configuration and should  be added to project properties.
            //app.UseExceptionHandler("/error.html");

            //if (configuration.GetValue<bool>("FeatureToggle:EnableDeveloperExceptions")) // bool converting
            //{
            //    app.UseDeveloperExceptionPage();

            //}

            //app.UseRouting();
            ////app.Use(async (context, next)=>
            ////{
            ////    if (context.Request.Path.Value.StartsWith("/Hello"))
            ////    {
            ////        await context.Response.WriteAsync("Hello it's ASP.NET Core");
            ////    }

            ////    await next();
            ////});
            //app.Use(async (context, next) =>
            //{
            //    if (context.Request.Path.Value.Contains("invalid"))
            //        throw new Exception("Error!!!!");

            //    await next();
            //});
            ////app.UseEndpoints(endpoints =>
            ////{
            ////    endpoints.MapGet("/", async context =>
            ////    {
            ////        await context.Response.WriteAsync("Hello ASP.Net Core!");
            ////    });
            ////});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync(" Hello !!!!!");
            //});

            //app.UseStaticFiles();
        }
Ejemplo n.º 17
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, FeatureToggles features)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //app.Use(async (context, next) =>
            //{
            //    if(context.Request.Path.Value.StartsWith("/hello"))
            //    {
            //        await context.Response.WriteAsync("Hello World! ASP.NET Core");
            //    }
            //    await next();
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            app.UseExceptionHandler("/error.html");

            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            //if (_configuration["EnableDeveloperExceptions"] == "True")
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            //if (_configuration.GetValue<bool>("FeatureToggles:DeveloperExceptions"))
            //{
            //    app.UseDeveloperExceptionPage();
            //}


            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseIdentity();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default", "{controller=Home}/{action=Index}/{Id:int?}"

                                );
            });

            app.UseFileServer();

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.StartsWith("/invalid"))
                {
                    throw new Exception("error");
                }
                await next();
            });
        }
Ejemplo n.º 18
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FeatureToggles features)
        {
            //ERROR must go to properties > Debug and change enviroment
            app.UseExceptionHandler("/error.html");

            if (features.DeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapGet("/", async context =>
            //    {
            //        await context.Response.WriteAsync("HELLOW!");
            //    });
            //});


            #region Middleware App Use
            //app.Use(async (context, next) =>
            //{
            //    if (context.Request.Path.Value.StartsWith("/hello"))
            //    {
            //        await context.Response.WriteAsync("TEST Hello");
            //    }

            //    await next();
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("TEST");
            //});
            #endregion

            #region Error - bad practice and security issue
            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });
            #endregion



            #region Adding MVC
            app.UseMvc(routes =>
            {
                routes.MapRoute("Default",
                                "{controller=Home}/{action=Index}/{id?}"
                                );
            });
            #endregion


            #region When serving static files like CSS/Images - wwwroot
            app.UseFileServer();
            #endregion
        }
Ejemplo n.º 19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //The ASP.NET pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, FeatureToggles features)
        {//at runtime the FeatureTogges class gets insyantiated and injected by .net core's dependency injection framework.
         //then it can be used in the code to determine what the dev options are, without knowing or caring where the values came from
         //*see if statement below

            loggerFactory.AddConsole();

            //this middleware function below listens to any exception that may occur then redirects to the error static page
            //of course this gets called first since it's the first middleware in the pipeline
            //this shows the end user a simple error page.
            //to view this error page change the environment in the projects properties from dev to prod
            //or have it read for the json file
            app.UseExceptionHandler("/error.html");

            //to use the configuration api using environment variables - an instance of the
            //configuration builder object must be created and import
            //its namespace 'using Microsoft.Extensions.Configuration;'
            //--------------------tightly coupled--The configuration object was moved to a property and populated in the Startup ctor
            //Note: Dependency Injection is a development pattern that encourages loue coupliing between components
            //Note: This code below is tightly coupled to the conffiguration API, since is has to know everything
            //about where these configuration values come from and how to read them from the configuration object.
            ///var configuration = new ConfigurationBuilder()
            //another configuration source, using json files. Add a json call in the configuration builder
            //with the path the the json config file, which needs to be created in the root of the project.
            /// .AddJsonFile(env.ContentRootPath + "/config.json")
            ///.AddJsonFile(env.ContentRootPath + "/config.dev.json", true)//the true flag tells the
            //config api that if a file does not exist then keep on going with the existing config file.
            //true is an optional switch
            ///.AddEnvironmentVariables()
            ///.Build();

            // if (configuration.GetValue<bool>("FeaturesToggle:EnableDevExceptions"))//this is looking at the json file
            if (features.EnableDeveloperExceptions) //for this DI to be used the service needs to be added in the ConfigureServices
                                                    //which allows you to configure your DI logic
            {
                app.UseDeveloperExceptionPage();
            }
            //---------------------tightly coupled

            /*
             *
             * if (configuration["EnableDevMode"]=="false") //this env dev variable was set in the project configurations with a true value
             *  //now when I set this to true it will show the dev error page, if I set the env variable to false it will display the error html page
             *  //basically setting this to false will skip the registration of the developer exception page 'UseDeveloperExceptionPage'
             * {
             *  //if the environment is dev then display a more detailed error page - for devs only.
             *  app.UseDeveloperExceptionPage();
             * }
             *
             */

            app.Use(async(context, next) => {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }
                await next();
            });


            /*********************************************************** Middleware
             *          app.Use(async (context, next) =>
             *          {
             *              //if the browser url matches /hello the output msg Hello world2
             *              //and then process the next middle ware request, hello world!!!
             *              //else, it process the next function Hello world!!!
             *              if (context.Request.Path.Value.StartsWith("/hello"))
             *              {
             *                  await context.Response.WriteAsync("Hello World123");
             *              }
             *              await next();
             *          });
             *          app.Run(async (context) =>
             *          {
             *              await context.Response.WriteAsync("Hello World!!!!");
             *          });
             ***********************************************************************/


            //Register the StaticFiles middleware component which tells asp net core to try and map
            //any unhandled requests to a file in the wwwroot folder, if that file exists go aheaed and serve it.
            //this mapping even includes defaut pages such as an index.html.
            //You can use the static files middleware to render any kind of static content that you'd like.
            app.UseFileServer();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              FeatureToggles featureToggles)
        {
            app.UseExceptionHandler("/error.html");

            /*This exception middleware used raised error then redirect to error page
             * Change the ENV veriable then actual error page*/
            if (featureToggles.DeveloperException)
            {
                app.UseDeveloperExceptionPage();
            }

            //if (configuration.GetValue<bool>["EnableDeveloperExceptionPage"] == true)
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            /**Handled the exception handling*/
            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("new throw Error..!!");
                }

                await next();
            });
            /*Configure routes in core 2.0*/
            //app.UseMvc(routes =>
            //{
            //    routes.MapRoute("Default",
            //                    "{controller=Home}/{action=Index}/id");
            //});
            /*Configure routes in core 3.1*/
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            /*Middle Ware :Use contain from wwwroot folder Use file server or serve static files*/
            app.UseFileServer();


            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapGet("/", async context =>
            //    {
            //        if (context.Request.Path.Value.StartsWith("/hello"))
            //        {
            //            await context.Response.WriteAsync("Hello asp.net core World!");
            //        }
            //        else
            //        {
            //            await context.Response.WriteAsync("Hello asp.net core World!22");
            //        }

            //    });
            //});
        }
Ejemplo n.º 21
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, FeatureToggles features)
        {
            loggerFactory.AddConsole();

            app.UseExceptionHandler("/error.html");

            // Evaluating with the custom configurations files and environment variables
            if (features.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });

            // Calling the MVC Framework
            app.UseMvc(routes =>
            {
                routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id:int?}");
            });

            // Using the `Microsoft.AspNetCore.StaticFiles` to serve static files
            app.UseFileServer();
        }
        // 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, FeatureToggles feature)
        {
            loggerFactory.AddConsole();

            // telling ASP.NET Core's configuration library about the various places that the application's configuration settings will be stored.
            // true for optional


            app.UseExceptionHandler("/error.html");

            //use the configuration object just like a dictionary.
            if (feature.EnableDeveloperExceptions)
            {
                app.UseDeveloperExceptionPage();
            }

            //Generate Error for testing
            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("Error");
                }
                await next();
            });

            app.UseIdentity();

            app.UseMvc(routes => {
                routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
            });
            app.UseFileServer();
        }
Ejemplo n.º 23
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, FeatureToggles features)
        {
            loggerFactory.AddConsole();

            //if (env.IsDevelopment())
            //if (_configuration["EnableDeveloperExceptions"] == "True")
            //if (_configuration.GetValue<bool>("FeatureToggles:EnableDeveloperExceptions")) //config hodnota prevedena na pozadovany datovy typ
            if (features.DeveloperExceptions)    //citanie konfiguracie z custom triedy
            {
                app.UseDeveloperExceptionPage(); //zabezpecuje zobrazenie developerskej error page
            }
            else
            {
                app.UseExceptionHandler("/error.html");
            }

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.StartsWith("/invalid"))
                {
                    throw new Exception("Error");
                }

                await next();
            });

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

            app.UseFileServer(); //middleware sa pokusi zadanu URL previest na subor v wwwroot lokacii
            //wwwroot --> specialny folder oddelujuci staticke subory, ktore maju byt k dispozicii pre uzivatelov aplikacie od zvysku aplikacneho kodu


            //app.Use(async (context, next) => //Use + next --> definovania, ze ma byt po vykonani tohto middleware vykonany aj nasledujuci
            //{
            //    if (context.Request.Path.Value.StartsWith("/hello")) //middleware vykonany len pri urcitej URL
            //    {
            //        await context.Response.WriteAsync("Hello ASP.NET Core!");
            //    }
            //    await next();
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("How are you?");
            //});
        }
Ejemplo n.º 24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, FeatureToggles features)
        {
            #region handling and diagnostics
            // app.UseExceptionHandler("/error.html");
            #endregion

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            #region DependencyInjection
            //if (_configuration.GetValue<bool>("FeatureToggles:EnableDeveloperExceptions"))
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            //if (features.DeveloperExceptions)
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            #endregion

            #region Respond to HTTP Requests
            // context represents request
            // next is the next middleware function regisered in pipeline
            //app.Use(async (context, next) =>
            //{

            //    // Look for a pattern that starts with /hello
            //    if (context.Request.Path.Value.StartsWith("/hello"))
            //    {
            //        await context.Response.WriteAsync("Hello ASP.NET Core!");
            //    }

            //    await next();
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync(" How are you?!");
            //});
            #endregion

            #region Error handling and diagnostics demo
            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.Contains("invalid"))
                {
                    throw new Exception("ERROR!");
                }

                await next();
            });

            #endregion

            // Use Identity services
            // app.UseIdentity();

            #region Customize Application URL's
            app.UseMvc(routes =>
            {
                routes.MapRoute("Default",
                                "{controller=Home}/{action=Index}/{id?}");
            });



            #endregion
            #region Serving Static Files
            // looks at any url and tries to locate in wwwroot
            // registers static files
            app.UseFileServer();
            #endregion
        }