Asp.net mvc 从MVC WebApi中的url中删除index.html

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

我使用angular作为前端,我有一个index.html作为起始页

主页上的url如下所示:

localhost:588/index.html#/

我希望它看起来像:localhost:3478/#/或者只是localhost:3478/

问题是,在我的家庭控制器的索引方法中,我返回

    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();
    }
    
2-解决方案2:读取index.html内容并返回HTTP响应- 将以下内容用作控制器类中的索引操作:

    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不会出现在地址栏中