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,26 +298,37 @@ namespace Orchard.Azure {
|
|||||||
return "application/unknown";
|
return "application/unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
string applicationHost = System.Environment.ExpandEnvironmentVariables(@"%windir%\system32\inetsrv\config\applicationHost.config");
|
try {
|
||||||
if (File.Exists(applicationHost)) {
|
string applicationHost = System.Environment.ExpandEnvironmentVariables(@"%windir%\system32\inetsrv\config\applicationHost.config");
|
||||||
var xdoc = XDocument.Load(applicationHost);
|
string webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/").FilePath;
|
||||||
var mimeMap = xdoc.XPathSelectElements("//staticContent/mimeMap[@fileExtension='" + extension + "']").FirstOrDefault();
|
|
||||||
if(mimeMap != null) {
|
// search for custom mime types in web.config and applicationhost.config
|
||||||
var mimeType = mimeMap.Attribute("mimeType");
|
foreach (var configFile in new[] {webConfig, applicationHost}) {
|
||||||
if(mimeType != null) {
|
if (File.Exists(configFile)) {
|
||||||
return mimeType.Value;
|
var xdoc = XDocument.Load(configFile);
|
||||||
|
var mimeMap = xdoc.XPathSelectElements("//staticContent/mimeMap[@fileExtension='" + extension + "']").FirstOrDefault();
|
||||||
|
if (mimeMap != null) {
|
||||||
|
var mimeType = mimeMap.Attribute("mimeType");
|
||||||
|
if (mimeType != null) {
|
||||||
|
return mimeType.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// search into the registry
|
// search into the registry
|
||||||
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(extension.ToLower());
|
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(extension.ToLower());
|
||||||
if (regKey != null) {
|
if (regKey != null) {
|
||||||
var contentType = regKey.GetValue("Content Type");
|
var contentType = regKey.GetValue("Content Type");
|
||||||
if (contentType != null) {
|
if (contentType != null) {
|
||||||
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