我在一些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;
}
2012-11-28
Erji