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 w3svc = new DirectoryEntry("IIS://localhost/MimeMap"))
{
w3svc.RefreshCache();
var mimeMaps = w3svc.Properties["MimeMap"];
var mimeMap = mimeMaps.OfType<IISMimeType>().FirstOrDefault(mt => mt.Extension == extension);
if (mimeMap != null)
mimeMaps.Remove(mimeMap);
mimeMap = new MimeMap { Extension = extension };
mimeMap.MimeType = mimeType;
mimeMaps.Add(mimeMap);
w3svc.CommitChanges();
}
}
Kommentare zum Snippet