1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/// <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();
}
}
|