Asp.net mvc 从MVC WebApi中的url中删除index.html
我使用angular作为前端,我有一个index.html作为起始页 主页上的url如下所示: localhost:588/index.html#/ 我希望它看起来像:localhost:3478/#/或者只是localhost:3478/ 问题是,在我的家庭控制器的索引方法中,我返回Asp.net mvc 从MVC WebApi中的url中删除index.html,asp.net-mvc,angularjs,model-view-controller,Asp.net Mvc,Angularjs,Model View Controller,我使用angular作为前端,我有一个index.html作为起始页 主页上的url如下所示: localhost:588/index.html#/ 我希望它看起来像:localhost:3478/#/或者只是localhost:3478/ 问题是,在我的家庭控制器的索引方法中,我返回 public ActionResult Index() { //return File("index.html", "text/html"); //retu
public ActionResult Index()
{
//return File("index.html", "text/html");
//return ActionResult("~/index.html");
//return new RedirectResult("~/index.html", true);
return Redirect(Url.Content("index.html"));
}
我想不出任何其他方法来让它工作。我如何解决我的问题
注:注释外代码是我尝试过的,但它不起作用。1-解决方案1:
- 将index.html移动到~/shared文件夹并将其重命名为index.cshtml
- 在控制器中使用以下各项:
public ActionResult Index() { return View(); }
public ActionResult index()
{
var myHtmlFile = Server.MapPath("~/Index.html");
if (!System.IO.File.Exists(myHtmlFile))
{
return HttpNotFound();
}
return Content(System.IO.File.ReadAllText(myHtmlFile), "text/html");
}
在这两种情况下,您都可能需要更改路径以访问index.html/cshtml文件中的image、css和.js资源,但这并不是什么大问题,因为index.html不会出现在地址栏中