Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Joey Kincer 51 posts 83 karma points
    Aug 11, 2022 @ 22:18
    Joey Kincer
    0

    KML/KMZ MIME type configuration not working

    Using Umbraco 10 (.NET 6) with IIS. Trying to load a .kmz (Google Maps) file from \wwwroot\media\ into a page but it's throwing a 404, even after defining the .kml/.kmz MIME types in IIS as well as in the web.config.

    My previous setup using the same .kmz file in Umbraco 7 worked fine.

    My hosting provider's support couldn't figure it out either, but they were able to load their own local .kmz file elsewhere on the server and assumed it was .NET Core or Umbraco preventing the file from loading properly.

    Is there a proper way to declare the .kmz MIME type within a .NET Core project? Is there some kind of MiddleWare or FileExtensionContentTypeProvider trickery in order to make it work? (I only have surface-level knowledge of .NET core so not too versed in potential solutions for this specific situation.)

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 12, 2022 @ 05:34
  • Joey Kincer 51 posts 83 karma points
    Aug 13, 2022 @ 20:25
    Joey Kincer
    0

    Yep, it's .NET Core related. Had to add it via the StartUp.cs file. Not even Umbraco-related. Learned something new!

    var provider = new FileExtensionContentTypeProvider();
    provider.Mappings.Add(".kml", "application/vnd.google-earth.kml+xml");
    provider.Mappings.Add(".kmz", "application/vnd.google-earth.kmz");
    
    app.UseStaticFiles(new StaticFileOptions
    {
        ContentTypeProvider = provider
    });
    
  • Warren Harding 132 posts 275 karma points
    Jun 13, 2023 @ 00:11
    Warren Harding
    0

    While this works great, it's breaking dynamic image resizing - don't suppose you have discovered a soution for that? Thanks

  • Anton David 5 posts 94 karma points
    Nov 24, 2023 @ 10:51
    Anton David
    0

    Hi All, I have the same problem with .run file. I added similar lines to fix that problem but looks like this is breaking the MediaProtect functionality, anyone can download the .run (all protected files) file if they have the link. Any idea how to fix this? Thank you Anton

  • Anton David 5 posts 94 karma points
    Nov 28, 2023 @ 10:22
    Anton David
    0

    If anyone encounters a similar problem, I placed the code after

    app.UseUmbraco() {...
    ...
    } 
    

    section in the Startup.cs file and it functioning correctly.

    Thanks Anton

  • Chris Clancy 65 posts 134 karma points
    Apr 09, 2024 @ 13:24
    Chris Clancy
    0

    Thanks for the info. I had a lot of trouble getting this working without breaking the image crops - or rather images were just displaying at random sizes rather than any errors going off.

    This code worked for the MIME type but broke the cropper:

    app.UseUmbraco()
        .WithMiddleware(u =>
        {
            u.UseBackOffice();
            u.UseWebsite();
        })
        .WithEndpoints(u =>
        {
            u.UseInstallerEndpoints();
            u.UseBackOfficeEndpoints();
            u.UseWebsiteEndpoints();
    
        });
    
    //for additional mime types - this will bstop cropped images displaying properly!
    
    var provider = new FileExtensionContentTypeProvider();
    provider.Mappings.Add(".msg", "application/vnd.ms-outlook");
    app.UseStaticFiles(new StaticFileOptions
    {
        ContentTypeProvider = provider
    });
    

    This code works for the MIME types without breaking the cropper:

    app.UseUmbraco()
        .WithMiddleware(u =>
        {
            u.UseBackOffice();
            u.UseWebsite();
        })
        .WithEndpoints(u =>
        {
            u.UseInstallerEndpoints();
            u.UseBackOfficeEndpoints();
            u.UseWebsiteEndpoints();
    
        });
    
    // Set up custom content types -associating file extension to MIME type
    var provider = new FileExtensionContentTypeProvider();
    // Add new mappings
    provider.Mappings.Add(".msg", "application/vnd.ms-outlook");
    
    app.UseStaticFiles(new StaticFileOptions()
    {
        ContentTypeProvider = provider
    });
    
  • Yakov Lebski 591 posts 2347 karma points
    Apr 09, 2024 @ 22:27
    Yakov Lebski
    3

    I preffer to not call app.UseStaticFiles and I my opinion Composer is better place to do it

     public class CoreComposer : IComposer
     {
         public void Compose(IUmbracoBuilder builder)
         {
    
             var contentTypeProvider = new FileExtensionContentTypeProvider();
             if (!contentTypeProvider.Mappings.ContainsKey(".kml"))
             {
                 contentTypeProvider.Mappings.Add(".kml", "vnd.google-earth.kml+xml");
             }
    
             builder.Services.Configure<StaticFileOptions>(options => options.ContentTypeProvider = contentTypeProvider);
         }
     }
    
  • David Armitage 510 posts 2081 karma points
    26 days ago
    David Armitage
    0

    Thanks. This solution worked well

Please Sign in or register to post replies

Write your reply to:

Draft