mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
#18705: Reading mimetype information from web.config when saving blobs in Azure
These mimetypse settings are originally used by IIS itself to get the mimetype
of specific files on the file system. We also then use it in AzureFileSystem to
assign a mime type to the blob to make it comprehensive.
<system.webServer>
<staticContent>
<remove fileExtension=".ogg" />
<mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
</staticContent>
</system.webServer>
Work Item: 18705
--HG--
branch : 1.x
This commit is contained in:
@@ -298,17 +298,23 @@ namespace Orchard.Azure {
|
||||
return "application/unknown";
|
||||
}
|
||||
|
||||
try {
|
||||
string applicationHost = System.Environment.ExpandEnvironmentVariables(@"%windir%\system32\inetsrv\config\applicationHost.config");
|
||||
if (File.Exists(applicationHost)) {
|
||||
var xdoc = XDocument.Load(applicationHost);
|
||||
string webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/").FilePath;
|
||||
|
||||
// search for custom mime types in web.config and applicationhost.config
|
||||
foreach (var configFile in new[] {webConfig, applicationHost}) {
|
||||
if (File.Exists(configFile)) {
|
||||
var xdoc = XDocument.Load(configFile);
|
||||
var mimeMap = xdoc.XPathSelectElements("//staticContent/mimeMap[@fileExtension='" + extension + "']").FirstOrDefault();
|
||||
if(mimeMap != null) {
|
||||
if (mimeMap != null) {
|
||||
var mimeType = mimeMap.Attribute("mimeType");
|
||||
if(mimeType != null) {
|
||||
if (mimeType != null) {
|
||||
return mimeType.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search into the registry
|
||||
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(extension.ToLower());
|
||||
@@ -318,6 +324,11 @@ namespace Orchard.Azure {
|
||||
return contentType.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// if an exception occured return application/unknown
|
||||
return "application/unknown";
|
||||
}
|
||||
|
||||
return "application/unknown";
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
|
||||
Reference in New Issue
Block a user