如何设置默认页面asp.net [英] How to set default page asp.net

查看:56
本文介绍了如何设置默认页面asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的服务器上发布了我的网站,但是当我在浏览器中输入 www.mysite.com 时,我收到此错误:HTTP 错误 403.14 - 禁止Web 服务器配置为不列出此目录的内容.但是,如果我键入 www.mysite.com/Home.aspx,它会正确加载.那么,如何设置默认页面?我的 web.config 中已经有了这个:

I've just published my site in my server, but when I type in the browser www.mysite.com I get this error : HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.However if I type www.mysite.com/Home.aspx it loads correctly. So, how can I set the default page?? I already have this in my web.config :

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

推荐答案

ASP.NET WebForms

web.config 文件上,尝试使用 clear 标记之前:

ASP.NET WebForms

On the web.config file, try this to use the clear tag before:

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

看看这里:http://www.iis.net/configreference/system.webserver/默认文档

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

Depending of the version of asp.net mvc you are using, you can have it on a different file (~/Global.asax.cs in v3 or older or ~/App_Start/RouteConfig.cs in v4 or newer). In both cases, you will see something register the routes, because asp.net mvc uses routes instead files like webforms. So, you can change the default values:

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
        }
    );
}

它在 ASP.NET CORE 上类似.

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

这篇关于如何设置默认页面asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆