public void Configuration(IAppBuilder app) { // STEP Map Folder Paths const string clientRootFolder = @"..\..\..\"; DirectoryInfo webDirectory = null; webDirectory = new DirectoryInfo(clientRootFolder + @"Sitter.Client\src\build"); ValidateDirectory(webDirectory); // Path to index var fsOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(webDirectory.FullName) }; app.UseFileServer(fsOptions); // Self-host the WebApi var config = new HttpConfiguration(); WebApiConfig.Register(config); IoCConfig.Register(config); app.UseWebApi(config); }
public DocfxSeedSiteFixture() { JObject token = JObject.Parse(File.ReadAllText(ConfigFile)); var folder = (string)token.SelectToken("site"); var port = (int)token.SelectToken("port"); Driver = new FirefoxDriver(); Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); Driver.Manage().Window.Maximize(); try { var contentTypeProvider = new FileExtensionContentTypeProvider(); // register yaml MIME as OWIN doesn't host it by default. // http://stackoverflow.com/questions/332129/yaml-mime-type contentTypeProvider.Mappings[".yml"] = "application/x-yaml"; var fileServerOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(folder), StaticFileOptions = { ContentTypeProvider = contentTypeProvider } }; Url = $"{RootUrl}:{port}"; WebApp.Start(Url, builder => builder.UseFileServer(fileServerOptions)); } catch (System.Reflection.TargetInvocationException) { Console.WriteLine($"Error serving \"{folder}\" on \"{Url}\", check if the port is already being in use."); } }
public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(@".\wwwroot"); FileServerOptions fileOptions = new FileServerOptions(); fileOptions.EnableDefaultFiles = true; fileOptions.RequestPath = PathString.Empty; fileOptions.FileSystem = physicalFileSystem; fileOptions.DefaultFilesOptions.DefaultFileNames = new[] {"Default.html"}; fileOptions.StaticFileOptions.FileSystem = fileOptions.FileSystem = physicalFileSystem; fileOptions.StaticFileOptions.ServeUnknownFileTypes = true; FormatterConfig.ConfigureFormatters(config.Formatters); RouteConfig.RegisterRoutes(config); appBuilder.UseWebApi(config); appBuilder.UseFileServer(fileOptions); //CORS & SignalR appBuilder.UseCors(CorsOptions.AllowAll); HubConfiguration configR = new HubConfiguration(); configR.EnableDetailedErrors = true; appBuilder.MapSignalR(configR); GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new SignalRUserIdProvider()); config.EnsureInitialized(); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { //Database.SetInitializer<ServerContext>(null); // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); appBuilder.UseWebApi(config); var physicalFileSystem = new PhysicalFileSystem(@"./wwwroot"); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; appBuilder.UseFileServer(options); }
public void Configuration(IAppBuilder app) { var appOptions = new FileServerOptions { RequestPath = new PathString("/app"), FileSystem = new PhysicalFileSystem("app"), EnableDefaultFiles = true }; appOptions.DefaultFilesOptions.DefaultFileNames.Add("index.html"); appOptions.StaticFileOptions.ServeUnknownFileTypes = true; app.UseFileServer(appOptions); var libsOptions = new FileServerOptions { RequestPath = new PathString("/libs"), FileSystem = new PhysicalFileSystem("libs") }; libsOptions.StaticFileOptions.ServeUnknownFileTypes = true; app.UseFileServer(libsOptions); app.UseErrorPage(); app.MapSignalR(); }
/// <summary> /// Enable all static file middleware with the given options /// </summary> /// <param name="builder"></param> /// <param name="options"></param> /// <returns></returns> public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, FileServerOptions options) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.EnableDefaultFiles) { builder = builder.UseDefaultFiles(options.DefaultFilesOptions); } if (options.EnableDirectoryBrowsing) { builder = builder.UseDirectoryBrowser(options.DirectoryBrowserOptions); } return builder .UseSendFileFallback() .UseStaticFiles(options.StaticFileOptions); }
// 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) { /* loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); */ var fileServerOptions = new FileServerOptions { EnableDefaultFiles = true, EnableDirectoryBrowsing = false }; //FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)fileServerOptions.StaticFileOptions.ContentTypeProvider; //contentTypeProvider.Mappings.Remove(".svg"); //contentTypeProvider.Mappings.Add(".svg", "image/svg+xml"); app.UseFileServer(fileServerOptions); //app.UseErrorPage(); // ToDo: Only route to this from /index.php/calendar/ app.UseStatusCodePagesWithRedirects("/#/WhenWhereModal"); }
public static void Serve(string folder, string port) { if (string.IsNullOrEmpty(folder)) folder = Environment.CurrentDirectory; folder = Path.GetFullPath(folder); port = string.IsNullOrWhiteSpace(port) ? "8080" : port; var url = $"http://localhost:{port}"; var fileServerOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(folder), }; if (!File.Exists(Path.Combine(folder, "index.html")) && File.Exists(Path.Combine(folder, "toc.html"))) { File.Copy(Path.Combine(folder, "toc.html"), Path.Combine(folder, "index.html")); } try { WebApp.Start(url, builder => builder.UseFileServer(fileServerOptions)); Console.WriteLine($"Serving \"{folder}\" on {url}"); Console.ReadLine(); } catch (System.Reflection.TargetInvocationException) { Logger.LogError($"Error serving \"{folder}\" on {url}, check if the port is already being in use."); } }
public DocfxSeedSiteFixture() { JObject token = JObject.Parse(File.ReadAllText(ConfigFile)); var folder = (string)token.SelectToken("site"); var port = (int)token.SelectToken("port"); Driver = new FirefoxDriver(); Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); Driver.Manage().Window.Maximize(); try { var fileServerOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(folder), }; Url = $"{RootUrl}:{port}"; WebApp.Start(Url, builder => builder.UseFileServer(fileServerOptions)); } catch (System.Reflection.TargetInvocationException) { Console.WriteLine($"Error serving \"{folder}\" on \"{Url}\", check if the port is already being in use."); } }
public void Configuration(IAppBuilder app) { /* // Note: Enable only for debugging. This slows down the perf tests. app.Use((context, next) => { var req = context.Request; context.TraceOutput.WriteLine("{0} {1}{2} {3}", req.Method, req.PathBase, req.Path, req.QueryString); return next(); });*/ app.UseErrorPage(new ErrorPageOptions { SourceCodeLineCount = 20 }); // app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]); app.UseSendFileFallback(); app.Use<CanonicalRequestPatterns>(); app.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString("/static"), FileSystem = new PhysicalFileSystem("public") }); app.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString("/static"), FileSystem = new PhysicalFileSystem("public") }); app.UseStageMarker(PipelineStage.MapHandler); FileServerOptions options = new FileServerOptions(); options.EnableDirectoryBrowsing = true; options.StaticFileOptions.ServeUnknownFileTypes = true; app.UseWelcomePage("/Welcome"); }
public void Configuration(IAppBuilder app) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); // Enable attribute based routing config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseCors(CorsOptions.AllowAll); app.UseWebApi(config); // Configure Web API for static files var physicalFileSystem = new PhysicalFileSystem(@".\www"); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; app.UseFileServer(options); }
public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(@".\wwwroot"); FileServerOptions fileOptions = new FileServerOptions(); fileOptions.EnableDefaultFiles = true; fileOptions.RequestPath = PathString.Empty; fileOptions.FileSystem = physicalFileSystem; fileOptions.DefaultFilesOptions.DefaultFileNames = new[] {"index.html"}; fileOptions.StaticFileOptions.FileSystem = fileOptions.FileSystem = physicalFileSystem; fileOptions.StaticFileOptions.ServeUnknownFileTypes = true; try { config.MessageHandlers.Add(new ProxyHandler(this.configSettings)); appBuilder.UseWebApi(config); appBuilder.UseFileServer(fileOptions); } catch (Exception e) { Trace.WriteLine(e); } }
public void Configuration(IAppBuilder appBuilder) { var physicalFileSystem = new PhysicalFileSystem(@"C:\Work\Advanced\ACSStarTrek\ACS.Client"); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; appBuilder.UseFileServer(options); HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); appBuilder.UseWebApi(config); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); var root = Directory.GetParent(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)).Parent.FullName; var physicalFileSystem = new PhysicalFileSystem(root); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "app\\index.html" }; app.UseFileServer(options); }
private void ConfigureFileServer(IAppBuilder app, HostConfig config) { // use a file server to serve all static content (js, css, content, html, ...) and also configure default files (eg: index.html to be the default entry point) // create file system that will locate the files var fileSystem = AggregateFileSystem.FromWebUiPhysicalPaths(config.RootDirectory); // setup default documents app.UseDefaultFiles(new DefaultFilesOptions { FileSystem = fileSystem, DefaultFileNames = new List<string> { "views/index.html" } }); // start file server to share website static content // wrapper around: StaticFiles + DefaultFiles + DirectoryBrowser var fileServerOptions = new FileServerOptions { EnableDirectoryBrowsing = false, FileSystem = fileSystem, }; fileServerOptions.StaticFileOptions.ContentTypeProvider = new FileServerContentTypeProvider(); app.UseFileServer(fileServerOptions); }
public void Configuration(IAppBuilder app) { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 //HttpConfiguration config = new HttpConfiguration(); //config.Routes.MapHttpRoute( // name: "DefaultWebApi", // routeTemplate: "api/{controller}/{id}", // defaults: new { id = RouteParameter.Optional } //); //app.UseWebApi(config); var physicalFileSystem = new PhysicalFileSystem(@"./Plugins"); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "Index.html" }; app.UseFileServer(options); app.MapSignalR(); }
public void Configuration(IAppBuilder app) { #if DEBUG //when things go south app.UseErrorPage(); #endif FileServerOptions fileServerOptions = new FileServerOptions() { RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(@".\\public"), }; //In order to serve json files fileServerOptions.StaticFileOptions.ServeUnknownFileTypes = true; fileServerOptions.StaticFileOptions.DefaultContentType = "text"; // Remap '/' to '.\public\'. // Turns on static files and public files. app.UseFileServer(fileServerOptions); app.UseStageMarker(PipelineStage.MapHandler); //Web Api HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); //Cause all the cool kids use JSON config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true; config.Formatters.Remove(config.Formatters.XmlFormatter); app.UseWebApi(config); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { var options = new FileServerOptions() { RequestPath = new PathString(""), FileSystem = new PhysicalFileSystem("client"), EnableDefaultFiles = true, EnableDirectoryBrowsing = true }; options.DefaultFilesOptions.DefaultFileNames.Add("index.html"); options.StaticFileOptions.ServeUnknownFileTypes = true; appBuilder.MapSignalR(); appBuilder.UseFileServer(options); var config = new HttpConfiguration(); ConfigureDependancyResolver(config); config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{employeeId}"); appBuilder.UseCors(CorsOptions.AllowAll); appBuilder.UseWebApi(config); }
/// <summary> /// Enable all static file middleware with the given options /// </summary> /// <param name="app"></param> /// <param name="configureOptions"></param> /// <returns></returns> public static IApplicationBuilder UseFileServer(this IApplicationBuilder app, Action<FileServerOptions> configureOptions) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (configureOptions == null) { throw new ArgumentNullException(nameof(configureOptions)); } var fileServerOptions = new FileServerOptions(); configureOptions(fileServerOptions); if (fileServerOptions.EnableDefaultFiles) { app = app.UseDefaultFiles(options => { options = fileServerOptions.DefaultFilesOptions; }); } if (fileServerOptions.EnableDirectoryBrowsing) { app = app.UseDirectoryBrowser(options => { options = fileServerOptions.DirectoryBrowserOptions; }); } return app.UseStaticFiles(options => { options = fileServerOptions.StaticFileOptions; }); }
public static void UseSwaggerUi( this IApplicationBuilder app, string basePath = "swagger/ui") { ThrowIfServicesNotRegistered(app.ApplicationServices); basePath = basePath.Trim('/'); var indexPath = basePath + "/index.html"; // Enable redirect from basePath to indexPath app.UseMiddleware<RedirectMiddleware>(basePath, indexPath); // Serve indexPath via middleware app.UseMiddleware<SwaggerUiMiddleware>(indexPath); // Serve all other swagger-ui assets as static files var options = new FileServerOptions(); options.RequestPath = "/" + basePath; options.EnableDefaultFiles = false; options.StaticFileOptions.ContentTypeProvider = new FileExtensionContentTypeProvider(); options.FileProvider = new EmbeddedFileProvider( typeof(SwaggerUiBuilderExtensions).GetTypeInfo().Assembly, "Swashbuckle.SwaggerUi.bower_components.swagger_ui.dist"); app.UseFileServer(options); }
public void EmbeddedFileSystemDefaultFilesConfiguration(IAppBuilder app) { FileServerOptions options = new FileServerOptions(); options.FileSystem = new EmbeddedResourceFileSystem(Assembly.GetExecutingAssembly().GetName().Name); options.DefaultFilesOptions.DefaultFileNames.Clear(); options.DefaultFilesOptions.DefaultFileNames.Add("RequirementFiles.EmbeddedResources.SampleHTM.htm"); app.UseFileServer(options); }
public static void AddMimeTypes(FileServerOptions opts,IList<string> tdefs) { var ctp = new Microsoft.Owin.StaticFiles.ContentTypes.FileExtensionContentTypeProvider(); foreach (var def in tdefs) { var d = def.Split(';'); ctp.Mappings["." + d[0]] = d[1]; } opts.StaticFileOptions.ContentTypeProvider = ctp; }
// 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) { //use session app.UseSession(); app.UseFileServer(); var provider = new PhysicalFileProvider( Path.Combine(_contentRootPath, "node_modules") ); var _fileServerOptions = new FileServerOptions(); _fileServerOptions.RequestPath = "/node_modules"; _fileServerOptions.StaticFileOptions.FileProvider = provider; _fileServerOptions.EnableDirectoryBrowsing = true; app.UseFileServer(_fileServerOptions); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); // app.UseDatabaseErrorPage(); // app.UseBrowserLink(); //} //else //{ // app.UseExceptionHandler("/Home/Error"); //} app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage"); app.UseExceptionHandler("/Home/Error"); app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseFacebookAuthentication(new FacebookOptions() { AppId = Configuration["Authentication:Facebook:AppId"], AppSecret = Configuration["Authentication:Facebook:AppSecret"] }); app.UseMvc(routes => { routes.MapRoute( name: "areaAdmin", template: "{area:exists}/{controller}/{action}/{id?}", defaults: new {controller="Home", action = "Index" } ); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); //SampleData.InitializeDatabaseAsync(app.ApplicationServices).Wait(); }
public void Configuration(IAppBuilder app) { var fileSystem = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(Path.GetFullPath(Settings.PostsOutput)) }; app.UseFileServer(fileSystem); }
private void SetUpStaticFileHosting(IAppBuilder appBuilder) { var options = new FileServerOptions { RequestPath = new PathString("/wwwroot"), EnableDirectoryBrowsing = true }; appBuilder.UseFileServer(options); appBuilder.UseStaticFiles(); }
public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); if (Config.Global.EnableBasicAuth) { app.Use(typeof(AuthenticationMiddleware)); } if (Config.Global.EnableAttributeRouting) { config.MapHttpAttributeRoutes(); } config.Formatters.Remove(config.Formatters.XmlFormatter); config.Formatters.Add(config.Formatters.JsonFormatter); config.Services.Replace(typeof(IAssembliesResolver), new ApiAssemblyResolver()); if (Config.Global.EnableCors) { app.UseCors(CorsOptions.AllowAll); } if (Config.Global.EnableSignalR) { app.MapSignalR(); } if (Config.Global.EnableNLog) { app.UseNLog(); } if (Config.Global.EnableStaticFiles) { var root = $"{AppDomain.CurrentDomain.BaseDirectory}/{"www"}"; var fileServerOptions = new FileServerOptions() { EnableDefaultFiles = true, EnableDirectoryBrowsing = false, RequestPath = new PathString("/www"), FileSystem = new PhysicalFileSystem(root) }; app.UseFileServer(fileServerOptions); } app.UseWebApi(config); }
public void FixtureSetup() { var root = System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "..", "..", "Html"); var options = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(root) }; WebApp.Start(HOST_BASE, builder => builder.UseFileServer(options)); }
public void Configuration(IAppBuilder app) { var options = new FileServerOptions() { EnableDefaultFiles = true, RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(@".\web") }; app.UseFileServer(options); }
public void Configuration(IAppBuilder app) { //if (BuildConfiguration == ConfigurationType.Dev) //{ // webDirectory = new DirectoryInfo(clientRootFolder + @"Sitter.Client\src"); //} //else if (BuildConfiguration == ConfigurationType.Prod) //{ //webDirectory = new DirectoryInfo(clientRootFolder + @"Sitter.Client\build"); //webDirectory = new DirectoryInfo(@"C:\_git\avocado\Main\src\Sitter.Client\src"); //} var config = new HttpConfiguration(); //config.Filters.Add(new AuthenticationFilter()); WebApiConfig.Register(config); IoCConfig.Register(config); app.UseWebApi(config); app.UseCors(CorsOptions.AllowAll); // STEP Map Folder Paths const string clientRootFolder = @"C:\_github\sitter\Main\src\"; DirectoryInfo webDirectory = null; BuildConfiguration = ConfigurationType.Dev; if (BuildConfiguration == ConfigurationType.Dev) { webDirectory = new DirectoryInfo(clientRootFolder + @"Sitter.Client\src"); } else if (BuildConfiguration == ConfigurationType.Prod) { webDirectory = new DirectoryInfo(clientRootFolder + @"Sitter.Client\build"); if (!IsValidateDirectory(webDirectory)) { // TODO JFK: Standardize hosting paths webDirectory = new DirectoryInfo(@"C:\SitterAppDeploy\appclient"); } } var isValid = IsValidateDirectory(webDirectory); if (!isValid) return; // Path to index var fsOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(webDirectory.FullName) }; fsOptions.StaticFileOptions.ContentTypeProvider = new TcsTypeProvider(); app.UseFileServer(fsOptions); }
public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); var container = CreateKernel(); _backgroundTicker = new BackgroundTicker(container.Resolve<IHubMessageService>()); app.UseAutofacMiddleware(container).UseAutofacWebApi(config); app.MapSignalR(); WebApiConfig.Register(config); app.UseWebApi(config); var physicalFileSystem = new PhysicalFileSystem(@".."); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; app.UseFileServer(options); ActorSystem StatsActorSystem = container.Resolve<IActorSystemFactory>().Create("StatsCoordinatorActor"); MongoDbPersistence.Instance.Apply(StatsActorSystem); BsonClassMap.RegisterClassMap<CreateHitterMessage>(cm => { cm.AutoMap(); }); BsonClassMap.RegisterClassMap<HitHomeRunMessage>(cm => { cm.AutoMap(); }); BsonClassMap.RegisterClassMap<HomeRunHitEvent>(cm => { cm.AutoMap(); }); BsonClassMap.RegisterClassMap<HitterAddedEvent>(cm => { cm.AutoMap(); }); StatsActors stats = container.Resolve<StatsActors>(); stats.statActorRef = StatsActorSystem.ActorOf(StatsActorSystem.DI().Props<StatsCoordinatorActor>() .WithRouter(new RoundRobinPool(2)), "StatsCoordinatorActor"); stats.statCommandActorRef = StatsActorSystem.ActorOf(StatsActorSystem.DI().Props<StatsCoordinatorCommandActor>(), "StatsCoordinatorCommandActor"); stats.statViewActorRef = StatsActorSystem.ActorOf(StatsActorSystem.DI().Props<StatsCoordinatorViewActor>(), "StatsCoordinatorViewActor"); }
public void Configuration(IAppBuilder app) { // Configure Web API for self-host. var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Adding to the pipeline with our own middleware app.Use(async(context, next) => { // Add Header context.Response.Headers["Product"] = "Web Api Self Host"; // Call next middleware await next.Invoke(); }); // Custom Middleare app.Use(typeof(CustomMiddleware)); // Web Api app.UseWebApi(config); // Fik var options = new FileServerOptions { EnableDirectoryBrowsing = true, EnableDefaultFiles = true, DefaultFilesOptions = { DefaultFileNames = { "index.html" } }, FileSystem = new PhysicalFileSystem(System.Configuration.ConfigurationManager.AppSettings["location"]), StaticFileOptions = { ContentTypeProvider = new CustomContentTypeProvider() } }; app.UseFileServer(options); }
/// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// </summary> public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; }); app.UseDeveloperExceptionPage(); var indexSettings = new IndexSettings(); indexSettings.JSConfig.SwaggerEndpoints.Add(new EndpointDescriptor() { Url = "/v1/swagger.json", Description = "Cosmos DB API v1.0.0" }); indexSettings.JSConfig.SwaggerEndpoints.Add(new EndpointDescriptor() { Url = "/v2/swagger.json", Description = "Cosmos DB API v2.0.0" }); var fileServerOptions = new FileServerOptions() { FileProvider = new SwaggerUIFileProvider(indexSettings.ToTemplateParameters()), EnableDefaultFiles = true }; fileServerOptions.StaticFileOptions.ContentTypeProvider = new FileExtensionContentTypeProvider(); app.UseFileServer(fileServerOptions); app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(builder => builder .AllowAnyHeader() .AllowAnyMethod() .SetIsOriginAllowed((host) => true) .AllowCredentials() ); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSpaStaticFiles(); app.UseSpa(spa => { spa.Options.SourcePath = "FrontEnd"; }); FileServerOptions defaultFileOptions = new FileServerOptions(); defaultFileOptions.DefaultFilesOptions.DefaultFileNames.Clear(); defaultFileOptions.DefaultFilesOptions.DefaultFileNames.Add("index.html"); app.UseFileServer(defaultFileOptions); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "FrontEnd/dist")), }); }
public void Configuration(IAppBuilder appBuilder) { var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); #if DEBUG var physicalFileSystem = new PhysicalFileSystem(@"..\..\Web"); #else var physicalFileSystem = new PhysicalFileSystem("Web"); #endif var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; appBuilder.UseFileServer(options); Bootstrapper.Init(); config.DependencyResolver = new AutofacWebApiDependencyResolver(Bootstrapper.Container); appBuilder.UseAutofacMiddleware(Bootstrapper.Container); appBuilder.UseAutofacWebApi(config); appBuilder.UseWebApi(config); }
public DocfxSeedSiteFixture() { JObject token = JObject.Parse(File.ReadAllText(ConfigFile)); var folder = (string)token.SelectToken("site"); var port = (int)token.SelectToken("port"); Url = $"{RootUrl}:{port}"; Driver = new FirefoxDriver(); Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); Driver.Manage().Window.Maximize(); try { var contentTypeProvider = new FileExtensionContentTypeProvider(); // register yaml MIME as OWIN doesn't host it by default. // http://stackoverflow.com/questions/332129/yaml-mime-type contentTypeProvider.Mappings[".yml"] = "application/x-yaml"; var fileServerOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem(folder), StaticFileOptions = { ContentTypeProvider = contentTypeProvider } }; WebApp.Start(Url, builder => builder.UseFileServer(fileServerOptions)); } catch (System.Reflection.TargetInvocationException) { Console.WriteLine($"Error serving \"{folder}\" on \"{Url}\", check if the port is already being in use."); } catch (Exception e) { Console.WriteLine($"Error serving \"{folder}\" on \"{Url}\": {e}"); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // this will serve up wwwroot app.UseFileServer(); // this will serve up node_modules var provider = new PhysicalFileProvider(Path.Combine(_contentRootPath, "node_modules")); var _fileServerOptions = new FileServerOptions(); _fileServerOptions.RequestPath = "/node_modules"; _fileServerOptions.StaticFileOptions.FileProvider = provider; _fileServerOptions.EnableDirectoryBrowsing = true; app.UseFileServer(_fileServerOptions); AutoMapperConfiguration.Configure(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AutomaticAuthenticate = true, AutomaticChallenge = true }); // Custom authentication middleware //app.UseMiddleware<AuthMiddleware>(); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); // Uncomment the following line to add a route for porting Web API 2 controllers. //routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); DbInitializer.Initialize(app.ApplicationServices, _applicationPath); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); FileServerOptions fileServerOptions = new FileServerOptions(); fileServerOptions.DefaultFilesOptions.DefaultFileNames.Clear(); fileServerOptions.DefaultFilesOptions.DefaultFileNames.Add("draganddropexample.html"); app.UseFileServer(fileServerOptions); app.UseStaticFiles(); //app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void Configuration(IAppBuilder app) { var physicalFileSystem = new PhysicalFileSystem(@".\"); //. = root, Web = your physical directory that contains all other static content, see prev step var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; app.UseFileServer(options); app.UseNancy(NancyConfig); app.UseStageMarker(PipelineStage.MapHandler); //FluentMapper.Initialize(config => //{ // config.AddMap(new CustomerDetailsModelMapper()); // config.AddMap(new SearchModelMapper()); // config.AddMap(new CheckBoxMapper()); //}); }
/// <summary> /// Enable all static file middleware with the given options /// </summary> /// <param name="app"></param> /// <param name="options"></param> /// <returns></returns> public static IApplicationBuilder UseFileServer(this IApplicationBuilder app, FileServerOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.EnableDefaultFiles) { app.UseDefaultFiles(options.DefaultFilesOptions); } if (options.EnableDirectoryBrowsing) { app.UseDirectoryBrowser(options.DirectoryBrowserOptions); } return(app.UseStaticFiles(options.StaticFileOptions)); }
public void Configuration(IAppBuilder appBuilder) { System.Net.ServicePointManager.DefaultConnectionLimit = 256; HttpConfiguration config = new HttpConfiguration(); FormatterConfig.ConfigureFormatters(config.Formatters); PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(@".\wwwroot"); FileServerOptions fileOptions = new FileServerOptions(); fileOptions.EnableDefaultFiles = true; fileOptions.RequestPath = PathString.Empty; fileOptions.FileSystem = physicalFileSystem; fileOptions.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; fileOptions.StaticFileOptions.FileSystem = fileOptions.FileSystem = physicalFileSystem; fileOptions.StaticFileOptions.ServeUnknownFileTypes = true; config.MapHttpAttributeRoutes(); appBuilder.UseWebApi(config); appBuilder.UseFileServer(fileOptions); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public static void ConfigureApp(IAppBuilder appBuilder) { // Configure Web API for self-host. var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); appBuilder.UseWebApi(config); var fileserverOptions = new FileServerOptions { EnableDefaultFiles = true }; fileserverOptions.StaticFileOptions.FileSystem = new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot")); fileserverOptions.StaticFileOptions.ServeUnknownFileTypes = true; fileserverOptions.StaticFileOptions.DefaultContentType = "text/plain"; appBuilder.UseFileServer(fileserverOptions); }
private static void UseFileServer(this IApplicationBuilder app, QuartzminOptions options) { IFileProvider fs; if (string.IsNullOrEmpty(options.ContentRootDirectory)) { fs = new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly(), "Content"); } else { fs = new PhysicalFileProvider(options.ContentRootDirectory); } var fsOptions = new FileServerOptions() { RequestPath = new PathString($"{options.VirtualPathRoot}/Content"), EnableDefaultFiles = false, EnableDirectoryBrowsing = false, FileProvider = fs }; app.UseFileServer(fsOptions); }
// This allows us to also serve up the SPA private static void ConfigureStaticFiles(IAppBuilder app, IAppSettings appSettings) { var appFolder = appSettings.AppPath; try { var fileSystem = new PhysicalFileSystem(appFolder); var options = new FileServerOptions { //EnableDirectoryBrowsing = true, EnableDefaultFiles = true, FileSystem = fileSystem }; app.UseFileServer(options); } catch (DirectoryNotFoundException) { Console.WriteLine( $"Error! \"AppPath\" specified in App.config does not exist: value is \"{appFolder}\"." + " GUI will not be served by this host."); } }
private FileServerOptions configureStaticFiles() { string path = Path.Combine(Directory.GetCurrentDirectory(), "Client"); if (Debugger.IsAttached) { path = @"..\..\Client"; } var physicalFileSystem = new PhysicalFileSystem(path); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; if (Debugger.IsAttached) { options.EnableDirectoryBrowsing = true; } options.DefaultFilesOptions.DefaultFileNames = new[] { "login.html" }; return(options); }
public void Configuration(IAppBuilder builder) { var container = IoCBootstrapper.Container; var http = container.Resolve <HttpConfiguration>(); http.DependencyResolver = new AutofacWebApiDependencyResolver(container); builder.UseCors(CorsOptions.AllowAll); builder.UseAutofacMiddleware(container); builder.UseAutofacWebApi(http); builder.UseWebApi(http); var options = new FileServerOptions { FileSystem = new PhysicalFileSystem(@"./www"), EnableDefaultFiles = true }; builder.UseFileServer(options); FluentValidationModelValidatorProvider.Configure(http); }
FileServerOptions GenerateFileServerConfig() { var folder = new DirectoryInfo(_settings.WwwRootFolder); Logger.Info($"Use public www root: {folder.FullName}"); var physicalFileSystem = new PhysicalFileSystem(folder.FullName); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.StaticFileOptions.ContentTypeProvider = new FileExtensionContentTypeProvider(); options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; return(options); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ); appBuilder.UseWebApi(config); var options = new FileServerOptions { EnableDirectoryBrowsing = true, EnableDefaultFiles = true, //DefaultFilesOptions = { DefaultFileNames = { "index.html" } }, FileSystem = new PhysicalFileSystem("Content\\DVDs") }; appBuilder.UseFileServer(options); }
public void ConfigureStaticFiles(IApplicationBuilder app) { var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider(); // Add new mappings provider.Mappings[".json"] = "text/json"; StaticFileOptions sfo = new StaticFileOptions() { ContentTypeProvider = provider }; app.UseStaticFiles(sfo); var fso = new FileServerOptions { FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "articles")), RequestPath = "/articles", EnableDirectoryBrowsing = false }; fso.StaticFileOptions.ContentTypeProvider = provider; app.UseFileServer(fso); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var options = new FileServerOptions(); options.StaticFileOptions.ContentTypeProvider = new FileExtensionContentTypeProvider() { Mappings = { { ".dae", "model/vnd.collada+xml" } } }; app.UseFileServer(options); app.UseSignalR(routes => { routes.MapHub <ColossusHub>("/colossushub"); }); }
public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //app.Use<ExceptionMiddleware>(); //config.Services.Replace(typeof(IExceptionHandler), new WebApiExceptionPassthroughHandler()); //config.Routes.MapHttpRoute(name: "Default", routeTemplate: "", defaults: new { controller = "Index" }); config.Routes.MapHttpRoute(name: "Login", routeTemplate: "login", defaults: new { controller = "Login" }); app.UseWebApi(config); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); string staticFileFolder = System.IO.Path.Combine(dir.Parent.Parent.Parent.FullName, "Server", "Webserver", "static"); FileServerOptions fileServerOptions = new FileServerOptions { EnableDefaultFiles = true, EnableDirectoryBrowsing = false, RequestPath = new PathString(""), FileSystem = new PhysicalFileSystem(staticFileFolder) }; app.UseFileServer(fileServerOptions); }
public virtual void Configure(IApplicationBuilder aspNetCoreApp) { FileServerOptions options = new FileServerOptions { EnableDirectoryBrowsing = AppEnvironment.DebugMode, EnableDefaultFiles = false }; options.DefaultFilesOptions.DefaultFileNames.Clear(); options.FileProvider = HostingEnvironment.WebRootFileProvider; string path = $@"/Files/V{AppEnvironment.AppInfo.Version}"; aspNetCoreApp.Map(path, innerApp => { if (AppEnvironment.DebugMode == true) { innerApp.UseMiddleware <AspNetCoreNoCacheResponseMiddleware>(); } else { innerApp.UseMiddleware <AspNetCoreCacheResponseMiddleware>(); } innerApp.UseXContentTypeOptions(); innerApp.UseXDownloadOptions(); innerApp.UseFileServer(options); }); aspNetCoreApp.Map("/Files", innerApp => { innerApp.UseMiddleware <AspNetCoreNoCacheResponseMiddleware>(); innerApp.UseXContentTypeOptions(); innerApp.UseXDownloadOptions(); innerApp.UseFileServer(options); }); }
private void UseFileServer(IAppBuilder app) { if (_configuration.EnableManagementWeb == ModuleBinding.False) { return; } try { const string path = "/managementweb"; var options = new FileServerOptions() { FileSystem = new PhysicalFileSystem(_configuration.ManagementWebLocation), RequestPath = new PathString(path), }; options.DefaultFilesOptions.DefaultFileNames.Add("index.html"); if (_configuration.EnableManagementWeb == ModuleBinding.Local) { app.Use(typeof(BlockNonLocalRequestsMiddleware), path); } options.StaticFileOptions.OnPrepareResponse = ctx => { ctx.OwinContext.Response.Headers.Append("X-Frame-Options", "DENY"); ctx.OwinContext.Response.Headers.Append("X-XSS-Protection", "1; mode=block"); }; app.UseFileServer(options); } catch (DirectoryNotFoundException) { // no admin web deployed - catch silently, but display info for the user _logger?.Information("The configured directory for the ManagementWeb was not found. ManagementWeb will be disabled."); } }
public void Configuration(IAppBuilder app) { //Enable CORS app.UseCors(CorsOptions.AllowAll); //Enable SignalR app.MapSignalR(); // Configure Web API for self-host and use it. var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); // File Server var fileOptions = new FileServerOptions { EnableDirectoryBrowsing = true, FileSystem = new PhysicalFileSystem("Jobs"), StaticFileOptions = { ContentTypeProvider = new ContentTypeProvider() }, RequestPath = new Microsoft.Owin.PathString("/Directory") }; app.UseFileServer(fileOptions); // Nancy var nancyOptions = new NancyOptions { Bootstrapper = new IDPJobManagerBootstrapper(JobPoolManager.Scheduler) }; app.UseNancy(nancyOptions); }
public void Configuration(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = AuthenticationType }); var apiConfig = new HttpConfiguration(); apiConfig.Routes.MapHttpRoute("default", "api/{controller}/{action}"); app.UseWebApi(apiConfig); var fileSystem = new PhysicalFileSystem("wwwroot"); var staticFilesConfig = new FileServerOptions { FileSystem = fileSystem }; staticFilesConfig.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; app.UseFileServer(staticFilesConfig); app.Run(context => { IFileInfo index; if (fileSystem.TryGetFileInfo("index.html", out index)) { context.Response.ContentType = "text/html"; return(context.Response.WriteAsync(ReadFully(index.CreateReadStream()))); } context.Response.ContentType = "text/plain"; return(context.Response.WriteAsync("OWIN here!")); }); }
public void Configuration(IAppBuilder app) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", //routeTemplate: "{controller}" routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true; const string rootFolder = "."; var fileSystem = new PhysicalFileSystem(rootFolder); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = fileSystem, EnableDirectoryBrowsing = true }; app.UseFileServer(options); string contentPath = Path.Combine(Environment.CurrentDirectory, @"..\.."); app.UseStaticFiles(new Microsoft.Owin.StaticFiles.StaticFileOptions() { RequestPath = new PathString(), FileSystem = new PhysicalFileSystem(contentPath) }); app.UseWebApi(config); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="browsePath"></param> /// <param name="settingsPath"></param> public static void UseFileLog(this IApplicationBuilder app, string browsePath = "/_Logs_", string settingsPath = "/_Settings_") { LOG.LoggerFactory.ServiceProvider = app.ApplicationServices; if (app.ApplicationServices.GetService <ILoggerFactory>().GetType() != typeof(LOG.LoggerFactory)) { throw new NotImplementedException($"Please use IServiceCollection.AddFileLogging first."); } LoggerSettings.LogRequestPath = browsePath; LoggerSettings.SettingsPath = settingsPath; if (string.IsNullOrEmpty(LoggerSettings.LogRequestPath)) { LoggerSettings.LogRequestPath = "/_Logs_"; } if (string.IsNullOrEmpty(LoggerSettings.SettingsPath)) { LoggerSettings.SettingsPath = "/_Settings_"; } var fileOption = new FileServerOptions { EnableDirectoryBrowsing = true, RequestPath = LoggerSettings.LogRequestPath, FileProvider = new PhysicalFileProvider(LoggerSettings.LogDirectory), }; fileOption.StaticFileOptions.OnPrepareResponse = (context) => { if (ContentTypes.Contains(context.Context.Response.ContentType)) { context.Context.Response.ContentType += "; charset=utf-8"; } }; fileOption.DirectoryBrowserOptions.Formatter = new HtmlDirectoryFormatter(); app.UseFileServer(fileOption); app.UseWhen(context => context.Request.Path.StartsWithSegments(LoggerSettings.SettingsPath), builder => builder.UseMiddleware <LoggerSettings>()); }
private static void Startup(IAppBuilder app) { HttpListener listener = (HttpListener)app.Properties["System.Net.HttpListener"]; listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm; HttpConfiguration config = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; config.EnableCors(); config.EnableSystemDiagnosticsTracing(); config.AddApiVersioning(); config.AddVersionedApiExplorer(); config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver(); config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; config.MapHttpAttributeRoutes(); config .EnableSwagger(c => { c.SingleApiVersion("v1", "A title for your API"); c.PrettyPrint(); }) .EnableSwaggerUi(); PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem("wwwroot"); FileServerOptions fileServerOptions = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; app.UseWebApi(config); app.UseFileServer(fileServerOptions); }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder app) { try { // configure webapi HttpConfiguration config = new HttpConfiguration(); config.EnableCors(new EnableCorsAttribute("*", "*", "*")); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); // setup fileserver string fileSaveDirectory = AppCommon.GetFileSaveDirectory(); Directory.CreateDirectory(fileSaveDirectory); if (!Directory.Exists(fileSaveDirectory)) { throw new Exception("Invalid FileSaveDirectory specified <" + fileSaveDirectory + ">."); } else { FileServerOptions fsOptions = new FileServerOptions(); fsOptions.RequestPath = PathString.Empty; fsOptions.FileSystem = new PhysicalFileSystem(fileSaveDirectory); app.UseFileServer(fsOptions); } } catch (Exception e) { string message = AppCommon.AppendInnerExceptionMessages("Configuration: " + e.Message, e); throw new Exception(message); } }
public void Configuration(IAppBuilder app) { /* // Note: Enable only for debugging. This slows down the perf tests. * app.Use((context, next) => * { * var req = context.Request; * context.TraceOutput.WriteLine("{0} {1}{2} {3}", req.Method, req.PathBase, req.Path, req.QueryString); * return next(); * });*/ app.UseErrorPage(new ErrorPageOptions { SourceCodeLineCount = 20 }); // app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]); app.UseSendFileFallback(); app.Use <CanonicalRequestPatterns>(); app.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString("/static"), FileSystem = new PhysicalFileSystem("public") }); app.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString("/static"), FileSystem = new PhysicalFileSystem("public") }); app.UseStageMarker(PipelineStage.MapHandler); FileServerOptions options = new FileServerOptions(); options.EnableDirectoryBrowsing = true; options.StaticFileOptions.ServeUnknownFileTypes = true; app.UseWelcomePage("/Welcome"); }
private static void ConfigureStaticFilesHosting(IAppBuilder app) { const string appZipResource = "dashboard-app.zip"; var appZipEmbeddedResourceName = Assembly.GetEntryAssembly().GetManifestResourceNames().FirstOrDefault(p => p.EndsWith(appZipResource)); if (appZipEmbeddedResourceName == null) { throw new NullReferenceException("Could not find dashboard-app.zip in the entry assembly. Please make sure dashboard-app.zip is included in your jobbr server project and build action is set to Embedded Resource"); } var stream = Assembly.GetEntryAssembly().GetManifestResourceStream(appZipEmbeddedResourceName); var zipFileSystem = SharpZipLibFileSystem.Open(stream); var wrapper = new FileSystemWrapper(zipFileSystem); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = wrapper, StaticFileOptions = { FileSystem = wrapper, ServeUnknownFileTypes = true }, DefaultFilesOptions = { DefaultFileNames = new[] { "index.html" } } }; app.UseFileServer(options); }