加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

如何设置默认页面asp.net

发布时间:2020-12-15 23:05:35 所属栏目:asp.Net 来源:网络整理
导读:参见英文答案 Set Default Page in Asp.net8个 我刚刚在我的服务器上发布了我的网站,但是当我输入浏览器www.mysite.com时,我收到这个错误:HTTP错误403.14 – 禁止 Web服务器配置为不列出此目录的内容.但是,如果我键入www.mysite.com/Home.aspx它正确加载.那
参见英文答案 > Set Default Page in Asp.net8个
我刚刚在我的服务器上发布了我的网站,但是当我输入浏览器www.mysite.com时,我收到这个错误:HTTP错误403.14 – 禁止
Web服务器配置为不列出此目录的内容.但是,如果我键入www.mysite.com/Home.aspx它正确加载.那么,我如何设置默认页面?我已经在我的web.config中有这个:
<system.webServer>
   <defaultDocument>
     <files>
       <add value="Pages/Home.aspx" />
     </files>
   </defaultDocument>
  </system.webServer>

解决方法

ASP.NET WebForms

在web.config文件中,尝试以前使用clear标签:

<system.webServer>
  <defaultDocument>
    <files>
      <clear />
      <add value="Pages/Home.aspx" />
    </files>
  </defaultDocument>
</system.webServer>

看看这里:http://www.iis.net/configreference/system.webserver/defaultdocument

ASP.NET MVC

根据您正在使用的asp.net mvc版本,您可以将其放在不同的文件(v3或更旧版本的?/ Global.asax.cs或v4或更新版本的?App_Start / RouteConfig.cs中).在这两种情况下,您将看到一些注册路由的东西,因为asp.net mvc使用路由,而不是Webforms等文件.因此,您可以更改默认值:

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

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

看看这里:http://www.codeproject.com/Articles/624181/Routing-Basics-in-ASP-NET-MVC

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读