微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何设置默认页面asp.net

参见英文答案 > 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐