相关疑难解决方法(0)

将index.html设置为默认页面

我有一个空的ASP.NET应用程序,我添加了一个index.html文件.我想将index.html设置为网站的默认页面.

我试图右键单击index.html并设置为起始页面,当我运行它时,url是:http://localhost:5134/index.html但我真正想要的是当我输入:时http://localhost:5134,它应该加载index.html页面.

我的路线配置:

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 = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-routing

30
推荐指数
4
解决办法
4万
查看次数

MVC4 - 有没有办法将根路由到"正常"未处理的html页面?

我有一个MVC4应用程序,但我主要用于WebAPI部分.我希望将一个"普通的旧HTML"文件发送回用户(然后使用KnockoutJS或KendoUI从webapi控制器中提取JSON).

我知道我可以这样做:

routes.IgnoreRoute("{page}.html");
Run Code Online (Sandbox Code Playgroud)

然后,如果我浏览到"localhost/index.html",它会成功返回我的.html页面.但是,我真的想映射"root"默认路径"localhost /"以返回我的index.html.

我试过这个:

routes.MapPageRoute("root", "", "~/index.html");
Run Code Online (Sandbox Code Playgroud)

但是这会引发错误:

没有为扩展名".html"注册的构建提供程序.您可以在machine.config或web.config中的<compilation> <buildProviders>部分注册一个.确保具有BuildProviderAppliesToAttribute属性,该属性包含值"Web"或"全部".

任何人对如何使这项工作有任何想法?我可以点击一个返回普通html页面的默认控制器,但是对于HTML页面来说,遍历整个ASP.NET堆栈似乎有些过分,然后只需调用WebAPI URL以返回ASP.NET堆栈获取页面模型的一些JSON数据.

我基本上只是想"跳过"所有MVC管道并让IIS将我发回html页面,好像它不是ASP.NET应用程序,或者至少做尽可能少的处理.

.net asp.net routes asp.net-mvc-4 knockout.js

10
推荐指数
1
解决办法
3413
查看次数