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,9 +298,14 @@ namespace Orchard.Azure {
|
|||||||
return "application/unknown";
|
return "application/unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
string applicationHost = System.Environment.ExpandEnvironmentVariables(@"%windir%\system32\inetsrv\config\applicationHost.config");
|
string applicationHost = System.Environment.ExpandEnvironmentVariables(@"%windir%\system32\inetsrv\config\applicationHost.config");
|
||||||
if (File.Exists(applicationHost)) {
|
string webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/").FilePath;
|
||||||
var xdoc = XDocument.Load(applicationHost);
|
|
||||||
|
// 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();
|
var mimeMap = xdoc.XPathSelectElements("//staticContent/mimeMap[@fileExtension='" + extension + "']").FirstOrDefault();
|
||||||
if (mimeMap != null) {
|
if (mimeMap != null) {
|
||||||
var mimeType = mimeMap.Attribute("mimeType");
|
var mimeType = mimeMap.Attribute("mimeType");
|
||||||
@@ -309,6 +314,7 @@ namespace Orchard.Azure {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// search into the registry
|
// search into the registry
|
||||||
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(extension.ToLower());
|
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(extension.ToLower());
|
||||||
@@ -318,6 +324,11 @@ namespace Orchard.Azure {
|
|||||||
return contentType.ToString();
|
return contentType.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// if an exception occured return application/unknown
|
||||||
|
return "application/unknown";
|
||||||
|
}
|
||||||
|
|
||||||
return "application/unknown";
|
return "application/unknown";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
Reference in New Issue
Block a user