Fügt einen neuen MimeType dem Server hinzu.
/// <summary>
/// Adds the MIME type.
/// </summary>
/// <param name = "extension">The extension.</param>
/// <param name = "mimeType">The MimeType.</param>
public void AddMimeType(string extension, string mimeType)
{
using (var serverManager = new ServerManager())
{
var config = serverManager.GetApplicationHostConfiguration();
var staticContentSection = config.GetSection("system.webServer/staticContent");
var staticContentCollection = staticContentSection.GetCollection();
var mimeMapElement = staticContentCollection.FirstOrDefault(ce => ce["fileExtension"].ToString() == extension);
if (mimeMapElement != null)
staticContentCollection.Remove(mimeMapElement);
mimeMapElement = staticContentCollection.CreateElement("mimeMap");
mimeMapElement["fileExtension"] = extension;
mimeMapElement["mimeType"] = mimeType;
staticContentCollection.Add(mimeMapElement);
serverManager.CommitChanges();
}
}
Kommentare zum Snippet