public void KnownExtensionsReturnTrye() { var provider = new FileExtensionContentTypeProvider(); string contentType; provider.TryGetContentType("known.txt", out contentType).ShouldBe(true); contentType.ShouldBe("text/plain"); }
public void DashedExtensionsShouldBeMatched() { var provider = new FileExtensionContentTypeProvider(); string contentType; provider.TryGetContentType("known.dvr-ms", out contentType).ShouldBe(true); contentType.ShouldBe("video/x-ms-dvr"); }
public void DashedExtensionsShouldBeMatched() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.True(provider.TryGetContentType("known.dvr-ms", out contentType)); Assert.Equal("video/x-ms-dvr", contentType); }
public void KnownExtensionsReturnTrye() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.True(provider.TryGetContentType("known.txt", out contentType)); Assert.Equal("text/plain", contentType); }
public void BothSlashFormatsAreUnderstood() { var provider = new FileExtensionContentTypeProvider(); string contentType; provider.TryGetContentType(@"/first/example.txt", out contentType).ShouldBe(true); contentType.ShouldBe("text/plain"); provider.TryGetContentType(@"\second\example.txt", out contentType).ShouldBe(true); contentType.ShouldBe("text/plain"); }
public void BothSlashFormatsAreUnderstood() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.True(provider.TryGetContentType(@"/first/example.txt", out contentType)); Assert.Equal("text/plain", contentType); Assert.True(provider.TryGetContentType(@"\second\example.txt", out contentType)); Assert.Equal("text/plain", contentType); }
public void DotsInDirectoryAreIgnored() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.True(provider.TryGetContentType(@"/first.css/example.txt", out contentType)); Assert.Equal("text/plain", contentType); Assert.True(provider.TryGetContentType(@"\second.css\example.txt", out contentType)); Assert.Equal("text/plain", contentType); }
public void DotsInDirectoryAreIgnored() { var provider = new FileExtensionContentTypeProvider(); string contentType; provider.TryGetContentType(@"/first.css/example.txt", out contentType).ShouldBe(true); contentType.ShouldBe("text/plain"); provider.TryGetContentType(@"\second.css\example.txt", out contentType).ShouldBe(true); contentType.ShouldBe("text/plain"); }
// Configure is called after ConfigureServices is called. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { var myProvider = new FileExtensionContentTypeProvider(); myProvider.Mappings.Add(".json", "application/json"); // Configure the HTTP request pipeline. app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = myProvider}); // Add MVC to the request pipeline. app.UseMvc(); // Add the following route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }
public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseMvc(builder => { builder.MapRoute(name: "defaultApi", template: "api/{controller}/{action}"); }); app.UseDefaultFiles(); var options = new StaticFileOptions(); var provider = new FileExtensionContentTypeProvider(); provider.Mappings.Add(".iso", "application/octet-stream"); options.ContentTypeProvider = provider; app.UseStaticFiles(options); }
// 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(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseIISPlatformHandler(); // Set up custom content types - associating file extension to MIME type var provider = new FileExtensionContentTypeProvider(); provider.Mappings.Add(".yaml", "text/yaml"); // Serve static files. app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider }); app.UseMvc(); }
public void DoubleDottedExtensionsAreNotSupported() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.False(provider.TryGetContentType("known.exe.config", out contentType)); }
protected virtual void ConfigureFileServer(IApplicationBuilder app) { var contentTypes = new FileExtensionContentTypeProvider(); contentTypes.Mappings[".js"] = "application/js"; contentTypes.Mappings[".json"] = "application/json"; contentTypes.Mappings[".map"] = "text/x-map"; contentTypes.Mappings[".scss"] = "text/x-scss"; var hostingEnvironment = app.ApplicationServices.GetService<IHostingEnvironment>(); var absoluteWebRootPath = Path.GetFullPath(hostingEnvironment.WebRootPath); var fileProviderList = new FileProviderList(); fileProviderList.Add(new PhysicalFileProvider(absoluteWebRootPath)); var jsonDataPath = Configuration.Get("jsonDataPath"); fileProviderList.Add( new RerootedFileProvider( new PhysicalFileProvider(jsonDataPath), "Json")); var videoPath = Configuration.Get("videoPath"); fileProviderList.Add( new RerootedFileProvider( new PhysicalFileProvider(videoPath), "Videos")); var videoPath2 = Configuration.Get("videoPath2"); if (!string.IsNullOrWhiteSpace(videoPath2)) { fileProviderList.Add( new RerootedFileProvider( new PhysicalFileProvider(videoPath2), "Videos")); } var soundsPath = Configuration.Get("soundsPath"); fileProviderList.Add( new RerootedFileProvider( new PhysicalFileProvider(soundsPath), "Sounds")); var musicPath = Configuration.Get("musicPath"); fileProviderList.Add( new RerootedFileProvider( new PhysicalFileProvider(musicPath), "Music")); var imagesPath = Configuration.Get("imagesPath"); fileProviderList.Add( new RerootedFileProvider( new PhysicalFileProvider(imagesPath), "Images")); var fileServerOptions = new FileServerOptions() { FileProvider = fileProviderList, EnableDirectoryBrowsing = (Configuration.Get("enableDirectoryBrowsing").ToLower().Equals("true")), EnableDefaultFiles = true, }; fileServerOptions.DefaultFilesOptions.DefaultFileNames = new[] { "Index.html", "index.html", }; fileServerOptions.DirectoryBrowserOptions.FileProvider = fileProviderList; fileServerOptions.StaticFileOptions.ContentTypeProvider = contentTypes; app.UseFileServer(fileServerOptions); }
public void UnknownExtensionsReturnFalse() { var provider = new FileExtensionContentTypeProvider(); string contentType; provider.TryGetContentType("unknown.ext", out contentType).ShouldBe(false); }
public void InvalidCharactersAreIgnored() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.True(provider.TryGetContentType($"{new string(System.IO.Path.GetInvalidPathChars())}.txt", out contentType)); }
public void UnknownExtensionsReturnFalse() { var provider = new FileExtensionContentTypeProvider(); string contentType; Assert.False(provider.TryGetContentType("unknown.ext", out contentType)); }
// Configure is called after ConfigureServices is called. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.MinimumLevel = LogLevel.Information; loggerFactory.AddConsole(); loggerFactory.AddDebug(); loggerFactory.AddEventLog(); var logger = loggerFactory.CreateLogger("ToprakWeb"); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseErrorPage(); } app.UseApplicationInsightsRequestTelemetry(); app.UseErrorHandler( errorApp => { var telemetryClient = new TelemetryClient(); errorApp.Run( async context => { context.Response.StatusCode = 200; context.Response.ContentType = "text/html"; await context.Response.WriteAsync("<html><body>\r\n"); await context.Response.WriteAsync( "Beklenmiyen bir hata olustu.<br>\r\n"); var error = context.GetFeature<IErrorHandlerFeature>(); if (error != null) { // This error would not normally be exposed to the client logger.LogCritical($"{error.Error.Message} \n {error.Error.StackTrace}"); } await context.Response.WriteAsync("<br><a href=\"/\">Home</a><br>\r\n"); await context.Response.WriteAsync("</body></html>\r\n"); await context.Response.WriteAsync(new string(' ', 512)); // Padding for IE }); }); app.UseApplicationInsightsExceptionTelemetry(); var adminEmails = this.config["adminEmails"]; var facebookAppId = this.config["FacebookAppId"]; if (string.IsNullOrEmpty(facebookAppId) && env.IsDevelopment()) { facebookAppId = this.config["AppSettings:FacebookAppId"]; } var facebookAppSecret = this.config["FacebookAppSecret"]; if (string.IsNullOrEmpty(facebookAppSecret) && env.IsDevelopment()) { facebookAppSecret = this.config["AppSettings:FacebookAppSecret"]; } app.UseToprakWebAuthentication( "ToprakWeb", (options) => { options.FacebookAppId = facebookAppId; options.FacebookAppSecret = facebookAppSecret; options.GoogleClientId = this.config["AppSettings:GoogleClientId"]; options.GoogleClientSecret = this.config["AppSettings:GoogleClientSecret"]; options.AdminIds = adminEmails.Split(','); }); app.UseDefaultFiles(); var staticFileOptions = new StaticFileOptions(); var typeProvider = new FileExtensionContentTypeProvider(); if (!typeProvider.Mappings.ContainsKey(".woff2")) { typeProvider.Mappings.Add(".woff2", "application/font-woff2"); } staticFileOptions.ContentTypeProvider = typeProvider; app.UseStaticFiles(staticFileOptions); app.UseMvc(); app.UseApplicationInsightsExceptionTelemetry(); }
// 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(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>() .CreateScope()) { serviceScope.ServiceProvider.GetService<ApplicationDbContext>() .Database.Migrate(); } } catch { } } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); // add .tsx files as static files // http://docs.asp.net/en/latest/fundamentals/static-files.html var provider = new FileExtensionContentTypeProvider(); provider.Mappings.Add(".tsx", "application/javascript"); app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider }); app.UseIdentity(); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
/// <summary> /// Defaults to all request paths /// </summary> /// <param name="sharedOptions"></param> public StaticFileOptions(SharedOptions sharedOptions) : base(sharedOptions) { ContentTypeProvider = new FileExtensionContentTypeProvider(); OnPrepareResponse = _ => { }; }