コード例 #1
0
 public void DashedExtensionsShouldBeMatched()
 {
     var provider = new FileExtensionContentTypeProvider();
     string contentType;
     provider.TryGetContentType("known.dvr-ms", out contentType).ShouldBe(true);
     contentType.ShouldBe("video/x-ms-dvr");
 }
コード例 #2
0
 public void KnownExtensionsReturnTrye()
 {
     var provider = new FileExtensionContentTypeProvider();
     string contentType;
     provider.TryGetContentType("known.txt", out contentType).ShouldBe(true);
     contentType.ShouldBe("text/plain");
 }
コード例 #3
0
ファイル: DocfxSeedSiteFixture.cs プロジェクト: dotnet/docfx
        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.");
            }

        }
コード例 #4
0
 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");
 }
コード例 #5
0
 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");
 }
コード例 #6
0
        public static IAppBuilder UseStaticFilesServer(this IAppBuilder app, string path)
        {
            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings.Add(".odt", "application/vnd.oasis.opendocument.text");

            return app.UseStaticFiles(new StaticFileOptions()
            {
                FileSystem = new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Globals.Constants.RootFolder, Globals.Constants.Uploads)),
                //RequestPath = new PathString(path),
                ContentTypeProvider = provider
            });
        }
コード例 #7
0
ファイル: Startup.cs プロジェクト: JeroenRombouts/themes-gnap
        private void ConfigureStaticFileServer(IAppBuilder builder)
        {
            var contentTypeProvider = new FileExtensionContentTypeProvider();
            contentTypeProvider.Mappings.Add(".json", "application/json");

            var options = new FileServerOptions
            {
                EnableDirectoryBrowsing = true,
                EnableDefaultFiles = true,
                FileSystem = new PhysicalFileSystem(_staticFilesRoot)
            };

            options.DefaultFilesOptions.DefaultFileNames.Add("about.html");

            options.StaticFileOptions.ContentTypeProvider = contentTypeProvider;

            builder.UseFileServer(options);
        }
コード例 #8
0
 public void DoubleDottedExtensionsAreNotSupported()
 {
     var provider = new FileExtensionContentTypeProvider();
     string contentType;
     provider.TryGetContentType("known.exe.config", out contentType).ShouldBe(false);
 }
コード例 #9
0
 public void UnknownExtensionsReturnFalse()
 {
     var provider = new FileExtensionContentTypeProvider();
     string contentType;
     provider.TryGetContentType("unknown.ext", out contentType).ShouldBe(false);
 }