1

I am using angular for frontend and i have a index.html asa start page.

on main page url is looking like this:

localhost:588/index.html#/

and i want it to look like : localhost:3478/#/ or just localhost:3478/

The problem is that i n my Home controller´s Index method i return

    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"));
            }

And i cant figure out any other ways to make it work. How do i solve my problem?

P.S. outcommented code is something i tryed and it didnt work.

1 Answer 1

4

1-Solution 1:

  • Move index.html to ~/shared folder and rename it to index.cshtml
  • Use the following in your controller:

    public ActionResult Index()
    {          
        return View();
    }
    

2-Solution 2: Read index.html content and return to HTTP response - Use the following as your index action in your controller class:

    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");
    }

In both ways you may need to change the path to access image, css and.js resources in the index.html/cshtml file but that is not a big deal as instead index.html wont appear in address bar.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.