Si desea procesar este archivo index.htm en el navegador, entonces podría crear acción del controlador de esta manera:
public void GetHtml()
{
var encoding = new System.Text.UTF8Encoding();
var htm = System.IO.File.ReadAllText(Server.MapPath("/Solution/Html/") + "index.htm", encoding);
byte[] data = encoding.GetBytes(htm);
Response.OutputStream.Write(data, 0, data.Length);
Response.OutputStream.Flush();
}
o simplemente por:
public ActionResult GetHtml()
{
return File(Server.MapPath("/Solution/Html/") + "index.htm", "text/html");
}
lo que permite decir esta acción es en controlador principal y algunos http://yoursite.com/Home/GetHtml usuario pulsa entonces index.htm se representará.
EDIT: 2 otros métodos
Si desea ver el HTML puro de index.htm en el navegador:
public ActionResult GetHtml()
{
Response.AddHeader("Content-Disposition", new System.Net.Mime.ContentDisposition { Inline = true, FileName = "index.htm"}.ToString());
return File(Server.MapPath("/Solution/Html/") + "index.htm", "text/plain");
}
Si lo que desea es descargar el archivo:
public FilePathResult GetHtml()
{
return File(Server.MapPath("/Solution/Html/") + "index.htm", "text/html", "index.htm");
}
'Server.MapPath' no es necesario. simplemente intente 'return File (" ~/Html/index.htm "," text/html ");' –
¿Qué biblioteca necesita usar para usar 'File()'? –