You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置ASP.NET Entity Framework项目启动默认显示WebForm1

设置ASP.NET Web Forms启动默认显示WebForm1的方法

你用空模板创建的Web Forms项目默认没有配置路由,要设置启动时优先显示WebForm1,有几种直接可行的方法:

方法一:通过Visual Studio快速设置起始页

  • 在解决方案资源管理器中找到WebForm1.aspx文件
  • 右键点击该文件,选择设为起始页
  • 之后每次调试启动项目,都会自动打开这个页面,适合开发阶段快速配置

方法二:修改Web.config配置默认文档(部署后仍生效)

如果需要部署到服务器后也保持这个默认页规则,要修改项目根目录的Web.config文件:

  1. 找到或添加<system.webServer>节点
  2. 在节点内添加默认文档配置,指定WebForm1.aspx为默认打开页面:
<system.webServer>
  <defaultDocument>
    <files>
      <clear /> <!-- 清空原有默认文档列表,避免冲突 -->
      <add value="WebForm1.aspx" />
    </files>
  </defaultDocument>
</system.webServer>

可选:通过路由配置默认页(适合复杂URL场景)

如果需要用路由规则来指定默认页,需手动添加路由配置:

  1. 在项目根目录的Global.asax文件中,找到Application_Start方法,添加路由注册代码:
void Application_Start(object sender, EventArgs e)
{
    RouteConfig.RegisterRoutes(RouteTable.Routes);
}
  1. 在App_Code目录下创建RouteConfig.cs类,配置默认路由指向WebForm1:
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        // 配置根路径默认跳转至WebForm1.aspx
        routes.MapPageRoute("", "", "~/WebForm1.aspx");
    }
}

内容的提问来源于stack exchange,提问作者icecocotea

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 06:50:46