ASP. net mvc Tip #17-how to run an ASP. net mvc application

Source: Internet
Author: User

ASP. net mvc Tip #17-how to run an ASP. net mvc applicationProgram
ASP. net mvc Tip #17-how to run an ASP. net mvc application

Original American: http://weblogs.asp.net/stephenwalther/archive/2008/07/10/asp-net-mvc-tip-17-how-to-run-an-asp-net-mvc-application.aspx
Http://www.cnblogs.com/mike108mvp

Note: The translation level is limited. If there are any mistakes or mistakes in the translation, you are welcome to criticize and correct them. Thank you.

In this post, I will explain the different setting options from webform when running the ASP. NET MVC application in Visual Studio 2008. I recommend that you directly run the ASP. NET MVC application using ASP. NET development web server (the built-in Development Server of Visual Studio 2008.

An ASP. net mvc application works differently from a standard ASP. NET web forms application. When you request a URL, there may be no corresponding. aspx file in your hard disk. For example, assume that you request the following URL:

/Product/index. aspx

There is no reason to assume that the ASP. net mvc application contains a product folder or an index. aspx file in the product folder. The routing module in ASP. net mvc maps the request to a productcontroller controller by default and calls the index () method of productcontroller. Then, the index () method determines the rendering content returned to the view (View) (if there is a view) of the browser.

Therefore, running ASP. net mvc applications is more complex than running common ASP. NET web forms applications. In particular, you do not want to open the current page in a web browser. For example, if you have a file path: Views \ home \ index. aspx is enabled in Visual Studio 2008, and you press F5 to run your application, so you do not want to open this index in the Web browser. aspx file. The problem is that views \ home \ index. aspx does not correspond to a real path to display the index view. The actual path looks like/home/index. aspx. However, the actual path is determined by the URL routing module. It can be any path.

Set a start page

You can control what happens when you press F5 or Ctl-F5 by modifying the startup action settings of the ASP. net mvc project. In solution, right-click your project, select Properties menu options, and select Web options to view the startup options (see figure 1 ).

Figure 1-Modify startup options
Figure 1-modifying start options

There are two parts you can modify. The Start action section allows you to specify what will happen when an application is running. The options are:

· Current page-allows you to run the page currently being edited in Visual Studio.

· Specific page-allows you to set and run a specific page. You can set this page here, or right-click a solution page and choose set as start page ).

· Start an external program-allows you to run an external program.
· Start URL-allows you to request a URL. This option is often used when you create a web services application.

· Do not open a page-so that you can do nothing.

By default, an ASP. net mvc application is set to specific page. If you run an ASP. net mvc application, it will always open the development page (path is /).

An ASP. NET web forms application, in contrast, is set to current page by default. If a specific page is opened in Visual Studio, the page will be run.

Note: You can change the startup page of ASP. net mvc application to a specific page. For example, if you want to request a URL path/product/show/23 when your application starts, you can enter this URL in the input box of the specific page option.

You can also modify the servers option section. This part looks only for ASP. net mvc web application and ASP. NET web forms applications, rather than ASP. NET web sites. The most interesting setting in this section is to allow the edit and continue option. This setting is disabled by default. If you enable it, you can modify it in the application during debugging.Code. For example, you can set a breakpoint, run it to the breakpoint, modify your code, and press the continue button to continue, and the new modification will take effect immediately.

Run from ASP. NET development server
Running from the ASP. NET development server

I first learned the following tips from Brian Henderson. It is recommended that you right-click your asp. Net Development Server icon in the notification area of the taskbar and select the open in Web browser option (see figure 2 ). This suggestion means that after you open a browser window once, you keep the window open when you develop a website.

Figure 2-running from the ASP. NET development web server

 

Follow these steps:
Follow these steps:

(1) Right-click your project and choose Properties> Web tag> navigate to your project startup Item settings.
(2) set the startup to don't open a page.
(3) Enable the Enable Edit and continue option.
(4) Click the floppy disk icon to save your settings.

After you make these settings, click "debug"> "start debugging ", or click "debug" menu> "start without debugging" to open a new browser window. After you start running your application, you can open a new browser window from ASP. NET development server to view it (see figure 2 ).

 

What are the benefits of running your MVC application in this strange way? The main benefit is that you can keep your browser window open a specific page. You can keep your MVC application open (even during debugging ).

 

Generally, when you press F5 to open a new browser window to run an ASP. net mvc application, you must close the browser window to stop debugging. If you have already navigated to a specific page, and then when you run your application, you must start again every time and then navigate to the original specific page, this will waste a lot of time!

 

In contrast, if you open your browser from ASP. NET development server, you can keep your url address open in your MVC application. You can even stop your application, set a new breakpoint, and run your application again without closing the browser window.

 

Summary
Summary

 

In this post, I explained the project options that you can set when running an ASP. NET MVC application. I also recommend that you run your ASP. NET MVC application from the ASP. NET development server so that you can keep your url address unchanged when running the ASP. NET Website.
In this tip, I explained the project options that you can set for running an ASP. net MVC application. I also recommended that you run your asp. net MVC applications from the ASP. NET development server so that you can maintain your location in a running ASP.. NET web site.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.