/// <summary>
        /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
        /// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IAppBuilder.Properties.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IAppBuilder UseErrorPage(this IAppBuilder builder, ErrorPageOptions options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            string appMode   = new AppProperties(builder.Properties).Get <string>(Constants.HostAppMode);
            bool   isDevMode = string.Equals(Constants.DevMode, appMode, StringComparison.Ordinal);

            return(builder.Use <ErrorPageMiddleware>(options, isDevMode));
        }
示例#2
0
        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            // Configure the HTTP request pipeline.

            // Add the console logger.
            loggerfactory.AddConsole();

            // Add the following to the request pipeline only in development environment.
            if (env.IsEnvironment("Development"))
            {
                app.UseBrowserLink();
                //app.UseErrorPage(ErrorPageOptions.ShowAll);
                var errorPageOptions = new ErrorPageOptions();
                errorPageOptions.SourceCodeLineCount = 10;
                app.UseErrorPage(errorPageOptions);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

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

                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{controller}/{action}/{area}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="CustomErrorPageMiddleware" /> class
        /// </summary>
        /// <param name="next"></param>
        /// <param name="options"></param>
        /// <param name="isDevMode"></param>
        public CustomErrorPageMiddleware(AppFunc next, ErrorPageOptions options, ILogger logger, bool isDevMode)
        {
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (isDevMode)
            {
                options.SetDefaultVisibility(true);
            }

            this._next    = next;
            this._options = options;
            this._logger  = logger;
        }
示例#4
0
        public void Configuration(IAppBuilder app)
        {
            //app.Use() - (extension)void IAppBuilder.Use(Func<Microsoft.Owin.IOwinContext,Func<Task>,Task> handler)
            //app.Use((oc, nextFunc) => nextFunc());
            //app.Use(async (oc, nextFunc) => await nextFunc());
            app.Use((oc, nextFunc) =>
            {
                //Preprocess
                return(nextFunc());
            });

            app.Use((oc, nextFunc) =>
            {
                //Preprocess
                Task t = nextFunc();
                //Postprocess
                return(t);
            });

            app.Use(async(oc, nextFunc) =>
            {
                //Preprocess
                await nextFunc();
                //Postprocess
            });

            app.Use <IdentityPage>();
            app.UseIdentityPage();

            ErrorPageOptions options = new ErrorPageOptions();

            options.ShowCookies            = true;
            options.ShowEnvironment        = true;
            options.ShowHeaders            = true;
            options.ShowSourceCode         = true;
            options.ShowExceptionDetails   = true;
            app.Properties["host.AppMode"] = "development";
            app.UseErrorPage(options);



            //app.Run() - (extension)void IAppBuilder.Run(Func<Microsoft.Owin.IOwinContext,Task> handler)
            app.Run(oc => oc.Response.WriteAsync("Hello Katana post"));
            app.Run(async oc => await oc.Response.WriteAsync("Hello Katana post"));
            app.Run(oc =>
            {
                //Preprocess

                //string token = c.Authentication.User.Identity.Name;
                return(oc.Response.WriteAsync("Hello Katana"));
            });

            app.Run(oc =>
            {
                //Preprocess

                //string token = c.Authentication.User.Identity.Name;
                Task t = oc.Response.WriteAsync("Hello Katana");
                //Postprocess
                return(t);
            });
            app.Run(async oc =>
            {
                //Preprocess

                //string token = c.Authentication.User.Identity.Name;
                await oc.Response.WriteAsync("Hello Katana");
                //Postprocess
            });


            //app.Build();
            //app.New();
            //app.UseCookieAuthentication();
            //app.UseCors();
            //app.UseOAuthAuthorizationServer();
            //app.UseOAuthBearerAuthentication();
            //app.UseOAuthBearerTokens();
            //app.UseTwoFactorRememberBrowserCookie();
            //app.UseTwoFactorSignInCookie();
        }
示例#5
0
        /// <summary>
        /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
        /// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseErrorPage(this IApplicationBuilder builder, ErrorPageOptions options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            /* TODO: Development, Staging, or Production
             * string appMode = new AppProperties(builder.Properties).Get<string>(Constants.HostAppMode);
             * bool isDevMode = string.Equals(Constants.DevMode, appMode, StringComparison.Ordinal);*/
            bool isDevMode = true;

            return(builder.Use(next => new ErrorPageMiddleware(next, options, isDevMode).Invoke));
        }
        /// <summary>
        /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
        /// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder, ErrorPageOptions options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.UseMiddleware <DeveloperExceptionPageMiddleware>(options));
        }
示例#7
0
 /// <summary>
 /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
 /// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder, ErrorPageOptions options)
 {
     return(builder.UseMiddleware <ErrorPageMiddleware>(options));
 }
示例#8
0
        public void Configure(IApplicationBuilder app)
        {
            //load application-wide memory store
            Server server = new Server();

            //handle static files
            var options = new StaticFileOptions {
                ContentTypeProvider = new FileExtensionContentTypeProvider()
            };

            ((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add(new KeyValuePair <string, string>(".less", "text/css"));
            app.UseStaticFiles(options);

            //exception handling
            var errOptions = new ErrorPageOptions();

            errOptions.ShowSourceCode      = true;
            errOptions.SourceCodeLineCount = 10;
            errOptions.SetDefaultVisibility(true);
            errOptions.ShowExceptionDetails = true;
            errOptions.ShowEnvironment      = true;
            app.UseErrorPage();

            //use session (3 hour timeout)
            app.UseInMemorySession(configure: s => s.IdleTimeout = TimeSpan.FromMinutes(60 * 3));

            //run application
            app.Run(async(context) =>
            {
                var strings      = new Utility.Str(null);
                var requestStart = DateTime.Now;
                DateTime requestEnd;
                TimeSpan tspan;
                var path             = context.Request.Path.ToString();
                var paths            = path.Split("/"[0]).Skip(1).ToArray();
                String requestType   = "";
                var extension        = strings.getFileExtension(path);
                server.requestCount += 1;
                if (paths.Length > 1)
                {
                    if (paths[0] == "rennder")
                    {
                        //run a web service via ajax (e.g. /rennder/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();
                            }
                        }

                        //start the Web Service engine
                        var ws      = new Pipeline.WebService(server, context, paths, form);
                        requestType = "service";
                    }
                }

                if (requestType == "" && extension == "")
                {
                    //initial page request
                    var r       = new Pipeline.App(server, context);
                    requestType = "page";
                }

                if (requestType == "" && extension != "")
                {
                    //file
                    requestType = "file";
                }

                if (requestType == "")
                {
                    context.Response.ContentType = "text/html";
                    await context.Response.WriteAsync("Rennder is a drag & drop website CMS platform built for Windows, Linux, & Mac OSX.");
                }

                requestEnd          = DateTime.Now;
                tspan               = requestEnd - requestStart;
                server.requestTime += (tspan.Seconds);
                Console.WriteLine("GET {0} {1} ms {2}", context.Request.Path, tspan.Milliseconds, requestType);
            });
        }