如何在ASP中设置调试的启动页面。净MVC应用程序?

时间:2022-06-22 03:31:20

How do you start debugging the application at the application root? For example: http://localhost:49742/

如何开始在应用程序根上调试应用程序?例如:http://localhost:49742 /

I'm always getting a page which doesn't exist, such as: http://localhost:49742/Views/Home/About.aspx

我总是得到一个不存在的页面,比如:http://localhost:49742/Views/Home/About.aspx

Note that it would be OK to start at http://localhost:49742/Views/Home/About

注意,可以从http://localhost:49742/Views/Home/About开始

6 个解决方案

#1


189  

Go to your project's properties and set the start page property.

转到项目的属性并设置start page属性。

  1. Go to the project's Properties
  2. 转到项目的属性。
  3. Go to the Web tab
  4. 转到Web选项卡
  5. Select the Specific Page radio button
  6. 选择特定的页面单选按钮
  7. Type in the desired url in the Specific Page text box
  8. 在特定页面文本框中键入所需的url

#2


18  

While you can have a default page in the MVC project, the more conventional implementation for a default view would be to use a default controller, implememented in the global.asax, through the 'RegisterRoutes(...)' method. For instance if you wanted your Public\Home controller to be your default route/view, the code would be:

虽然在MVC项目中可以有一个默认的页面,但是默认视图的常规实现是使用默认的控制器,在全局中实现。asax,通过“注册路由(…)”方法。例如,如果您希望您的公共\Home控制器成为您的默认路由/视图,代码将是:

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

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Public", action = "Home", id = UrlParameter.Optional } // Parameter defaults
        );

    }

For this to be functional, you are required to have have a set Start Page in the project.

要使其具有功能性,您需要在项目中拥有一个set Start页面。

#3


9  

This works for me under Specific Page for MVC:

这适用于我在MVC的特定页面:

/Home/Index

Update: Currently, I just use a forward slash in the "Specific Page" textbox, and it takes me to the home page as defined in the routing:

更新:当前,我只是在“特定页面”文本框中使用了一个正斜杠,它将我带到了路由中定义的主页:

/

#4


5  

Selecting a specific page from Project properties does not solve my problem.

从项目属性中选择特定的页面并不能解决我的问题。

In MVC 4 open App_Start/RouteConfig.cs

在MVC 4中,打开App_Start/RouteConfig.cs

For example, if you want to change startup page to Login:

例如,如果要将启动页面更改为Login:

routes.MapRoute(
        "Default", // Route name
        "",        // URL with parameters
        new { controller = "Account", action = "Login"}  // Parameter defaults
    );

#5


1  

If you want to start at the "application root" as you describe right click on the top level Default.aspx page and choose set as start page. Hit F5 and you're done.

如果您想从“应用程序根”开始,如您所描述的那样,单击最顶层的默认值。aspx页面,选择set作为开始页面。命中F5,你就完成了。

If you want to start at a different controller action see Mark's answer.

如果您想从不同的控制器操作开始,请参阅Mark的答案。

#6


0  

Revisiting this page and I have more information to share with others.

重新浏览这个页面,我将有更多的信息与大家分享。

Debugging environment (using Visual Studio)

调试环境(使用Visual Studio)

1a) Stephen Walter's link to set the startup page on MVC using the project properties is only applicable when you are debugging your MVC application.

只有在调试MVC应用程序时,才能使用Stephen Walter的链接在MVC上使用项目属性设置启动页面。

1b) Right mouse click on the .aspx page in Solution Explorer and select the "Set As Start Page" behaves the same.

在“解决方案资源管理器”中,右键单击“.aspx”页面,并选择“设置为起始页”的行为。

Note: in both the above cases, the startup page setting is only recognised by your Visual Studio Development Server. It is not recognised by your deployed server.

注意:在上述两种情况下,只有Visual Studio开发服务器才能识别启动页面设置。您部署的服务器不能识别它。

Deployed environment

部署的环境

2a) To set the startup page, assuming that you have not change any of the default routings, change the content of /Views/Home/Index.aspx to do a "Server.Transfer" or a "Response.Redirect" to your desired page.

要设置启动页面,假设您没有更改任何默认路由,请更改/Views/Home/Index的内容。做一个“服务器”。转移”或“响应。重定向到你想要的页面。

2b) Change your default routing in your global.asax.cs to your desired page.

b)改变你在global.asax的默认路由。c到你想要的页面。

Are there any other options that the readers are aware of? Which of the above (including your own option) would be your preferred solution (and please share with us why)?

读者还知道其他选项吗?以上哪一个(包括你自己的选择)将是你的首选解决方案(请与我们分享为什么)?

#1


189  

Go to your project's properties and set the start page property.

转到项目的属性并设置start page属性。

  1. Go to the project's Properties
  2. 转到项目的属性。
  3. Go to the Web tab
  4. 转到Web选项卡
  5. Select the Specific Page radio button
  6. 选择特定的页面单选按钮
  7. Type in the desired url in the Specific Page text box
  8. 在特定页面文本框中键入所需的url

#2


18  

While you can have a default page in the MVC project, the more conventional implementation for a default view would be to use a default controller, implememented in the global.asax, through the 'RegisterRoutes(...)' method. For instance if you wanted your Public\Home controller to be your default route/view, the code would be:

虽然在MVC项目中可以有一个默认的页面,但是默认视图的常规实现是使用默认的控制器,在全局中实现。asax,通过“注册路由(…)”方法。例如,如果您希望您的公共\Home控制器成为您的默认路由/视图,代码将是:

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

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Public", action = "Home", id = UrlParameter.Optional } // Parameter defaults
        );

    }

For this to be functional, you are required to have have a set Start Page in the project.

要使其具有功能性,您需要在项目中拥有一个set Start页面。

#3


9  

This works for me under Specific Page for MVC:

这适用于我在MVC的特定页面:

/Home/Index

Update: Currently, I just use a forward slash in the "Specific Page" textbox, and it takes me to the home page as defined in the routing:

更新:当前,我只是在“特定页面”文本框中使用了一个正斜杠,它将我带到了路由中定义的主页:

/

#4


5  

Selecting a specific page from Project properties does not solve my problem.

从项目属性中选择特定的页面并不能解决我的问题。

In MVC 4 open App_Start/RouteConfig.cs

在MVC 4中,打开App_Start/RouteConfig.cs

For example, if you want to change startup page to Login:

例如,如果要将启动页面更改为Login:

routes.MapRoute(
        "Default", // Route name
        "",        // URL with parameters
        new { controller = "Account", action = "Login"}  // Parameter defaults
    );

#5


1  

If you want to start at the "application root" as you describe right click on the top level Default.aspx page and choose set as start page. Hit F5 and you're done.

如果您想从“应用程序根”开始,如您所描述的那样,单击最顶层的默认值。aspx页面,选择set作为开始页面。命中F5,你就完成了。

If you want to start at a different controller action see Mark's answer.

如果您想从不同的控制器操作开始,请参阅Mark的答案。

#6


0  

Revisiting this page and I have more information to share with others.

重新浏览这个页面,我将有更多的信息与大家分享。

Debugging environment (using Visual Studio)

调试环境(使用Visual Studio)

1a) Stephen Walter's link to set the startup page on MVC using the project properties is only applicable when you are debugging your MVC application.

只有在调试MVC应用程序时,才能使用Stephen Walter的链接在MVC上使用项目属性设置启动页面。

1b) Right mouse click on the .aspx page in Solution Explorer and select the "Set As Start Page" behaves the same.

在“解决方案资源管理器”中,右键单击“.aspx”页面,并选择“设置为起始页”的行为。

Note: in both the above cases, the startup page setting is only recognised by your Visual Studio Development Server. It is not recognised by your deployed server.

注意:在上述两种情况下,只有Visual Studio开发服务器才能识别启动页面设置。您部署的服务器不能识别它。

Deployed environment

部署的环境

2a) To set the startup page, assuming that you have not change any of the default routings, change the content of /Views/Home/Index.aspx to do a "Server.Transfer" or a "Response.Redirect" to your desired page.

要设置启动页面,假设您没有更改任何默认路由,请更改/Views/Home/Index的内容。做一个“服务器”。转移”或“响应。重定向到你想要的页面。

2b) Change your default routing in your global.asax.cs to your desired page.

b)改变你在global.asax的默认路由。c到你想要的页面。

Are there any other options that the readers are aware of? Which of the above (including your own option) would be your preferred solution (and please share with us why)?

读者还知道其他选项吗?以上哪一个(包括你自己的选择)将是你的首选解决方案(请与我们分享为什么)?