1

I've a ASP.NET MVC 4 Project and I have a subdirectory "test" in the root dir and it contains a index.html

I want wenn the clean URL is called that the index.html is returned

when I call

http://localhost:8080/

that I get the Content returned from my "test\index.html"

squadwuschel
  • 3,328
  • 3
  • 34
  • 45

2 Answers2

3

The RouteConfig class in the App_Start sub-directory should be adjusted so that the default Controller is Test. Place your 'test' directory within the Views directory and, if you haven't already, create a TestController. RouteConfig should look like this:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Test", action = "Index", id = UrlParameter.Optional }
        );
    }
}
Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
  • 1
    thats what I am looking for I've added a ActionResult in my TestController which returns => { return new FilePathResult("~/test/index.html", "text/html"); } – squadwuschel Nov 28 '16 at 18:07
1

The easiest way is to put your "test/index.html" as default document in IIS.

If you really want to do it programmatically you'll have to create an action to handle your request and map your default route to it.

Route:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "StaticFile", action = "Index", id = UrlParameter.Optional }
        );

Controller/Action:

public class StaticFileController : Controller
{
    // GET: StaticFile
    [AllowAnonymous]
    public FileContentResult Index()
    {
        string imageFile = System.Web.HttpContext.Current.Server.MapPath("~/Test/Index.html");
        byte[] bytes = System.IO.File.ReadAllBytes(imageFile);

        return File(bytes, "text/html");
    }
}
Douglas Gandini
  • 827
  • 10
  • 24