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.)
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
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
});
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);
}
}
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.)
Probably .net core
https://jakeydocs.readthedocs.io/en/latest/fundamentals/static-files.html#:~:text=The%20ASP.NET%20static%20file,return%20an%20HTTP%20404%20error.
Yep, it's .NET Core related. Had to add it via the StartUp.cs file. Not even Umbraco-related. Learned something new!
While this works great, it's breaking dynamic image resizing - don't suppose you have discovered a soution for that? Thanks
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
If anyone encounters a similar problem, I placed the code after
section in the Startup.cs file and it functioning correctly.
Thanks Anton
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:
This code works for the MIME types without breaking the cropper:
I preffer to not call app.UseStaticFiles and I my opinion Composer is better place to do it
is working on a reply...