我在一些javascripts,圖像和css的另一個目錄中有一些html文件。我想在我的網站中使用這些文件並限制用戶訪問該index.html鏈接。我在控制器操作中使用了返回File方法,但無法在該目錄上打開圖像,因此無法正常工作。什麼是適當的解決方案?你有想法嗎?如何從mvc中的另一個目錄中打開html文件
ps。 (當我調試的代碼,我看到JS,CSS和HTML文件可以用適當的MIME類型打開除JPG或PNG文件)
public ActionResult User(string name)
{
string file = (Server.MapPath(Url.Content("~/Content/Users/" + name)));
string path = Path.Combine(file);
string mime = GetMimeType(path);
return File(path, mime);
}
public string GetMimeType(string fileName)
{
string mimeType = "application/unknown";
string ext = Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
{
mimeType = regKey.GetValue("Content Type").ToString();
}
return mimeType;
}