【翻译】使用Visual Studio创建Asp.Net Core MVC (一)

简介: This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio 2015. 在这个范例里,我们将使用Visual Studio 2015创建基本的Asp.Net Core MVC网站。

This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio 2015.

在这个范例里,我们将使用Visual Studio 2015创建基本的Asp.Net Core MVC网站。

安装Visual Studio和.Net Core

创建一个Web应用

From the Visual Studio Start page, tap New Project.

在Visual Studio 起始页面,点击New Project

new_project.png

Alternatively, you can use the menus to create a new project. Tap File > New > Project.

你也可以通过菜单创建新项目。点击File > New Project

img_300bb51e7ae7feaa3ce57e22eb787875.png

Complete the New Project dialog:

在New Project对话框完成以下操作:

  • In the left pane, tap .NET Core
  • 在左侧面板,选择.Net Core
  • In the center pane, tap ASP.NET Core Web Application (.NET Core)
  • 在中间面板,选择Asp.Net Core web Application(.Net Core)
  • Name the project "MvcMovie" (It's important to name the project "MvcMovie" so when you copy code, the namespace will match.)
  • 项目取名:MvcMove(当你复制代码时,这个项目名称很重要,它跟命名空间相匹配)
  • Tap OK
  • 点击OK

img_6551edc90d7fcf7cf0bee7ff05d95436.png

Complete the New ASP.NET Core Web Application - MvcMovie dialog:

在New Asp.Net Core Web Application –MvcMovie对话框完成以下操作:

  • Tap Web Application
  • 点击Web Application
  • Clear Host in the cloud
  • 不勾选Host in the cloud
  • Tap OK.
  • 点击OK

img_c49854c0a147996708fcf485b2036a77.png

Visual Studio used a default template for the MVC project you just created, so you have a working app right now by entering a project name and selecting a few options. This is a simple "Hello World!" project, and it's a good place to start,Tap F5 to run the app in debug mode or Ctrl-F5 in non-debug mode.

Visual Studio会根据默认模板创建MVC项目,你只要输入一个项目名和选择几个选项就能创建。这是一个Hello World的项目,一个好的开始!点击F5debug模式应用或者Ctrl+F5非Debug模式运行。

img_d09d4461c221fcaec8f20b07eb47ffe2.png

  • Visual Studio starts IIS Express and runs your app. Notice that the address bar shows localhost:port# and not something like example.com. That's because localhost always points to your own local computer, which in this case is running the app you just created. When Visual Studio creates a web project, a random port is used for the web server. In the image above, the port number is 1234. When you run the app, you'll see a different port number.
  • Visual Studio将开启IIS Express运行你的应用。注意浏览器地址栏显示的是localhost:端口号而不是example.com,这是因为这种情况下运行刚创建的应用,localhost总是指向自己的电脑。当Visual Studio创建了一个web项目后,它将为web服务器随机一个端口号。以下图片上,显示的是1234端口,当你自己运行的时候,你看到的将是一个不同的端口号。
  • Launching the app with Ctrl+F5 (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.
  • 使用Ctrl+F5(非Debug模式)运行应用,允许你在更改代码,保存文件后,使用刷新页面就能看到你的改变。许多开发者都喜欢用non-debug模式快速运行应用和查看更改。
  • You can launch the app in debug or non-debug mode from the Debug menu item:
  • 你可以通过Debug菜单运行Debug和non-debug模式:

img_b251d63562fd0e39c3cb4b7083c06edb.png

  • You can debug the app by tapping the IIS Express button
  • 你也可以点击IIS Express按钮运行Debug模式

img_bc1376975bd694aee280a6875a873433.png

The default template gives you working Home, About and Contact links. The browser image above doesn't show these links. Depending on the size of your browser, you might need to click the navigation icon to show them.

默认模板有HOME,About和Contact三个链接。下图因为浏览器问题你看不到这几个链接,你可以通过点击导航图标显示。

img_61b569cfba765a677588f2e8e56848d0.png

If you were running in debug mode, tap Shift-F5 to stop debugging.

如果你运行在Debug模式下,Shift+F5停止Debug。

In the next part of this tutorial, we'll learn about MVC and start writing some code.

在这个范例的下一章节,我们将如何编写MVC代码。

原文链接

https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/first-mvc-app/start-mvc

相关文章
|
6天前
|
开发框架 监控 前端开发
在 ASP.NET Core Web API 中使用操作筛选器统一处理通用操作
【9月更文挑战第27天】操作筛选器是ASP.NET Core MVC和Web API中的一种过滤器,可在操作方法执行前后运行代码,适用于日志记录、性能监控和验证等场景。通过实现`IActionFilter`接口的`OnActionExecuting`和`OnActionExecuted`方法,可以统一处理日志、验证及异常。创建并注册自定义筛选器类,能提升代码的可维护性和复用性。
|
6天前
|
开发框架 .NET 中间件
ASP.NET Core Web 开发浅谈
本文介绍ASP.NET Core,一个轻量级、开源的跨平台框架,专为构建高性能Web应用设计。通过简单步骤,你将学会创建首个Web应用。文章还深入探讨了路由配置、依赖注入及安全性配置等常见问题,并提供了实用示例代码以助于理解与避免错误,帮助开发者更好地掌握ASP.NET Core的核心概念。
18 3
|
28天前
|
开发框架 NoSQL .NET
利用分布式锁在ASP.NET Core中实现防抖
【9月更文挑战第5天】在 ASP.NET Core 中,可通过分布式锁实现防抖功能,仅处理连续相同请求中的首个请求,其余请求返回 204 No Content,直至锁释放。具体步骤包括:安装分布式锁库如 `StackExchange.Redis`;创建分布式锁服务接口及其实现;构建防抖中间件;并在 `Startup.cs` 中注册相关服务和中间件。这一机制有效避免了短时间内重复操作的问题。
|
2月前
|
开发框架 监控 .NET
开发者的革新利器:ASP.NET Core实战指南,构建未来Web应用的高效之道
【8月更文挑战第28天】本文探讨了如何利用ASP.NET Core构建高效、可扩展的Web应用。ASP.NET Core是一个开源、跨平台的框架,具有依赖注入、配置管理等特性。文章详细介绍了项目结构规划、依赖注入配置、中间件使用及性能优化方法,并讨论了安全性、可扩展性以及容器化的重要性。通过这些技术要点,开发者能够快速构建出符合现代Web应用需求的应用程序。
35 0
|
2月前
|
开发框架 监控 .NET
【Azure 应用程序见解】在Docker中运行的ASP.NET Core应用如何开启Application Insights的Profiler Trace呢?
【Azure 应用程序见解】在Docker中运行的ASP.NET Core应用如何开启Application Insights的Profiler Trace呢?
|
2月前
|
网络安全 C++
【Azure Developer】Visual Studio 2019中如何修改.Net Core应用通过IIS Express Host的应用端口(SSL/非SSL)
【Azure Developer】Visual Studio 2019中如何修改.Net Core应用通过IIS Express Host的应用端口(SSL/非SSL)
|
2月前
|
Linux C# C++
【Azure App Service For Container】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务
【Azure App Service For Container】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务
|
2月前
|
开发框架 前端开发 .NET
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
36 0
|
2月前
|
开发框架 .NET API
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
|
2月前
|
开发框架 中间件 .NET
分享 ASP.NET Core Web Api 中间件获取 Request Body 两个方法
分享 ASP.NET Core Web Api 中间件获取 Request Body 两个方法
下一篇
无影云桌面