Exemplo n.º 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,
                              FeatureToggle 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.UseFileServer();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FeatureToggle featureToggle)
        {
            app.UseExceptionHandler("/error.html");

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

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

                await next();
            });

            app.UseAuthentication();

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

            app.UseFileServer();
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FeatureToggle features)
        {
            app.UseExceptionHandler("/error.html");
            // # # # 1. properties -> debug -> if (ENVIRONMENT = Development) => developer error page ( useful for dev )
            //                            else custom error page seen by user ( in this case error.html )
            // env.IsDevelopment() -> code used for first approach
            // 2. By using the configuration object ( creating Startup function ) the dev has more "freedom".
            // configuration.GetValue<bool>("EnableDeveloperExceptions") -> code used for second approach
            // dev can create env variable named EnableDeveloperExceptions... if there's no value in the config object it returns null
            // 3. The dev can update the json configuration object and then access the new setting in the json here
            // configuration.GetValue<bool>("FeatureToggles:DeveloperExceptions") -> code used for third approach ( : is used to access setting from json object, not . )
            // good practice, use a default json object for default settings and then create other json settings object...
            // 4. creating a instance of FeatureToggle object trough addTransient function in ConfigureServices function from which the json
            // setting is read and then used for this.
            // current code in the if -> code used for last approach
            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();
            });

            // # # # in the tutorial the guy uses app.UseMvc(... and routes.MapRoute(... instead of MapControllerRoute
            app.UseEndpoints(routes =>
            {
                routes.MapControllerRoute("Default",
                                          "{controller=Home}/{action=Index}/{id?}"
                                          );
            });

            // # # # This function is used for routing any request to the static html files from the project
            app.UseFileServer();
        }