asp.net mvc 中使用静态页

方法1:

在Global.asax文件中增加

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Context.Request.FilePath == "/") Context.RewritePath("index.html");
}

方法2:

新建一个路由DefaultController,并把它设置为默认路由,在Action中增加

Redirect(Url.Content("~/index.html"));

此方法需要修改web.config配置

在Web.config文件中的<compilation>节点中增加:

     <buildProviders>
        <add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
      </buildProviders>

  

方法3:

1)站点根目录增加了default.html;

2)修改Global.asax默认的路由注册,去掉默认controller:

routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new {action = "Index", id = UrlParameter.Optional } // 参数默认值
            ); 

 

将iis中的默认文档配置为index.html

转载于:https://www.cnblogs.com/mhdtysp/p/4347214.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值