Ejemplo n.º 1
0
        public static IAppBuilder UseHtml5Mode(this IAppBuilder app, string rootPath, string entryPath)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

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

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

            var options = new Html5ModeOptions
            {
                EntryPath         = new PathString(entryPath),
                FileServerOptions = new FileServerOptions()
                {
                    EnableDirectoryBrowsing = false,
                    FileSystem = new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rootPath))
                }
            };

            app.UseDefaultFiles(options.FileServerOptions.DefaultFilesOptions);

            return(app.Use(new Func <AppFunc, AppFunc>(next => new Html5ModeMiddleware(next, options).Invoke)));
        }
        public Html5ModeMiddleware(AppFunc next, Html5ModeOptions options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

            _options         = options;
            _innerMiddleware = new StaticFileMiddleware(next, options.FileServerOptions.StaticFileOptions);
            _entryPointAwareInnerMiddleware = new StaticFileMiddleware(
                environment =>
            {
                var context          = new OwinContext(environment);
                context.Request.Path = _options.EntryPath;
                return(_innerMiddleware.Invoke(environment));
            },
                options.FileServerOptions.StaticFileOptions);
        }