/// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 public ErrorPageMiddleware(
     [NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options, ILoggerFactory loggerFactory)
 {
     _next = next;
     _options = options;
     _logger = loggerFactory.CreateLogger<ErrorPageMiddleware>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 public ErrorPageMiddleware(
     [NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options, ILoggerFactory loggerFactory)
 {
     _next    = next;
     _options = options;
     _logger  = loggerFactory.CreateLogger <ErrorPageMiddleware>();
 }
 /// <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)
 {
     /* 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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 /// <param name="isDevMode"></param>
 public ErrorPageMiddleware([NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options, bool isDevMode)
 {
     if (isDevMode)
     {
         options.SetDefaultVisibility(isVisible: true);
     }
     _next = next;
     _options = options;
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 public ErrorPageMiddleware(
     [NotNull] RequestDelegate next,
     [NotNull] ErrorPageOptions options,
     ILoggerFactory loggerFactory,
     IApplicationEnvironment appEnvironment)
 {
     _next         = next;
     _options      = options;
     _logger       = loggerFactory.CreateLogger <ErrorPageMiddleware>();
     _fileProvider = options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 public ErrorPageMiddleware(
     [NotNull] RequestDelegate next,
     [NotNull] ErrorPageOptions options,
     ILoggerFactory loggerFactory,
     IApplicationEnvironment appEnvironment)
 {
     _next = next;
     _options = options;
     _logger = loggerFactory.CreateLogger<ErrorPageMiddleware>();
     _fileProvider = options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath);
 }
 /// <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 IBuilder.Properties.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IBuilder UseErrorPage(this IBuilder 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);
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 /// <param name="isDevMode"></param>
 public ErrorPageMiddleware(RequestDelegate next, ErrorPageOptions options, bool isDevMode)
 {
     if (next == null)
     {
         throw new ArgumentNullException("next");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     if (isDevMode)
     {
         options.SetDefaultVisibility(isVisible: true);
     }
     _next    = next;
     _options = options;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
 /// </summary>
 /// <param name="next"></param>
 /// <param name="options"></param>
 /// <param name="isDevMode"></param>
 public ErrorPageMiddleware(RequestDelegate next, ErrorPageOptions options, bool isDevMode)
 {
     if (next == null)
     {
         throw new ArgumentNullException("next");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     if (isDevMode)
     {
         options.SetDefaultVisibility(isVisible: true);
     }
     _next = next;
     _options = options;
 }
Beispiel #11
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?}");
            });
        }
        private ErrorPageMiddleware GetErrorPageMiddleware(
            IFileProvider fileProvider = null, int sourceCodeLineCount = 6)
        {
            var errorPageOptions = new ErrorPageOptions();

            errorPageOptions.SourceCodeLineCount = sourceCodeLineCount;

            if (fileProvider != null)
            {
                errorPageOptions.FileProvider = fileProvider;
            }

            var middleware = new ErrorPageMiddleware(
                (httpContext) => { return(Task.FromResult(0)); },
                errorPageOptions,
                new LoggerFactory(),
                new TestApplicationEnvironment());

            return(middleware);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DeveloperExceptionPageMiddleware"/> class
        /// </summary>
        /// <param name="next"></param>
        /// <param name="options"></param>
        public DeveloperExceptionPageMiddleware(
            RequestDelegate next,
            ErrorPageOptions options,
            ILoggerFactory loggerFactory,
            IApplicationEnvironment appEnvironment)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

            _next = next;
            _options = options;
            _logger = loggerFactory.CreateLogger<DeveloperExceptionPageMiddleware>();
            _fileProvider = options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath);
        }
Beispiel #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeveloperExceptionPageMiddleware"/> class
        /// </summary>
        /// <param name="next"></param>
        /// <param name="options"></param>
        public DeveloperExceptionPageMiddleware(
            RequestDelegate next,
            ErrorPageOptions options,
            ILoggerFactory loggerFactory,
            IApplicationEnvironment appEnvironment)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

            _next         = next;
            _options      = options;
            _logger       = loggerFactory.CreateLogger <DeveloperExceptionPageMiddleware>();
            _fileProvider = options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath);
        }
Beispiel #15
0
        private DeveloperExceptionPageMiddleware GetErrorPageMiddleware(
            IFileProvider fileProvider = null, int sourceCodeLineCount = 6)
        {
            var errorPageOptions = new ErrorPageOptions();

            errorPageOptions.SourceCodeLineCount = sourceCodeLineCount;

            if (fileProvider != null)
            {
                errorPageOptions.FileProvider = fileProvider;
            }

            var middleware = new DeveloperExceptionPageMiddleware(
                (httpContext) => { return(Task.FromResult(0)); },
                errorPageOptions,
                new LoggerFactory(),
                new TestApplicationEnvironment(),
                new DiagnosticListener("Microsoft.Aspnet"));

            return(middleware);
        }
        private DeveloperExceptionPageMiddleware GetErrorPageMiddleware(
            IFileProvider fileProvider = null, int sourceCodeLineCount = 6)
        {
            var errorPageOptions = new ErrorPageOptions();
            errorPageOptions.SourceCodeLineCount = sourceCodeLineCount;

            if (fileProvider != null)
            {
                errorPageOptions.FileProvider = fileProvider;
            }

            var middleware = new DeveloperExceptionPageMiddleware(
                (httpContext) => { return Task.FromResult(0); },
                errorPageOptions,
                new LoggerFactory(),
                new TestApplicationEnvironment(),
                new DiagnosticListener("Microsoft.Aspnet"));

            return middleware;
        }
Beispiel #17
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);
            });
        }
 /// <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);
 }