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

查看:147
本文介绍了如何设置默认页面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/defaultdocument

根据所使用的asp.net mvc版本,您可以将其放在另一个文件中(〜/ Global.asax.cs ,在v4或更高版本中为〜/ App_Start / RouteConfig.cs )。在这两种情况下,您都会看到一些注册路由的信息,因为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天全站免登陆