当前位置:网站首页>ASP.NET应用程序--Hello World
ASP.NET应用程序--Hello World
2022-08-05 02:58:00 【DXB2021】
安装 .NET 并创建首个 Web 应用程序。
本地预配向导和预配代理:
下载.NET SDK(软件开发安装包)
打开Windows PowerShell,输入命令行dotnet。
dotnet
运行结果如下:

如果安装成功,则会看到类似于以上内容的输出。
创建应用
在命令提示符,运行以下命令以创建应用:
dotnet new webapp -o MyWebApp --no-https -f net6.0
此命令是什么意思?
dotnet new 命令会新建一个应用程序。
webApp参数选择创建应用时要使用的模板。-o参数会创建名为MyWebApp的目录,用于存储应用。--no-https标记指定不启用 HTTPS。-f参数指示你正在创建 .NET 6 应用程序。

创建了哪些文件?
已在 MyWebApp 目录中创建多个文件,以为你提供可供运行的简单 Web 应用程序。
Program.cs包含应用启动代码和中间件配置。Pages目录包含应用程序的一些示例网页。MyWebApp.csproj会定义一些项目设置,例如要面向的 .NET SDK 版本。Properties目录中的launchSettings.json文件为本地开发环境定义不同的配置文件设置。创建项目时会自动分配 5000-5300 之间的端口号并将其保存在此文件上。

运行应用
在命令提示符中,导航到在上一步中新建的目录:
cd MyWebApp
然后,运行以下命令:
dotnet watch

等待应用显示正在侦听 http://localhost:<port number> 并等待浏览器在该地址启动。

恭喜你已生成并运行自己第一个 .NET Web 应用!
选择Ctrl+C,以随时停止应用。

编辑代码
编辑代码
在任意文本编辑器中打开位于 Pages 目录中的 Index.cshtml 文件。
输入代码之前:

代码如下:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
输入代码以后:

代码如下:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1>Hello,world!</h1>
<p>The time on the server is @DateTime.Now</p>
</div>
运行结果:



代码如下:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<h1>Hello, world!</h1>
<p>The time on the server is @DateTime.Now</p>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
运行结果如下:
边栏推荐
- Details such as compiling pretreatment
- tree table lookup
- Chinese characters to Pinyin
- The 22-07-31 weeks summary
- 2022-08-04: Input: deduplicated array arr, the numbers in it only contain 0~9.limit, a number.Return: The maximum number that can be spelled out with arr if the requirement is smaller than limit.from
- mysql can't Execute, please solve it
- QStyle平台风格
- PostgreSQL数据库 用navicat 打开表结构的时候报错 cannot update secondarysnapshot during a parallel operation 怎么解决?
- Use @Mapper to query the partition status of oracle and report an error
- Apache DolphinScheduler, a new generation of distributed workflow task scheduling platform in practice - Medium
猜你喜欢

View handler stepping record

A small tool to transfer files using QR code - QFileTrans 1.2.0.1
![[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)](/img/7b/8b3f1e4f0000aa34fc1f8fff485765.png)
[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)

金仓数据库如何验证安装文件平台正确性

QT MV\MVC结构

Data storage practice based on left-order traversal

J9 Digital Currency: What is the creator economy of web3?

Is your data safe in this hyperconnected world?

Apache DolphinScheduler, a new generation of distributed workflow task scheduling platform in practice - Medium

云原生(三十二) | Kubernetes篇之平台存储系统介绍
随机推荐
1484. Sell Products by Date
【Daily Training】1403. Minimum Subsequence in Non-Increasing Order
Use SuperMap iDesktopX data migration tool to migrate ArcGIS data
How OpenGL works
QT:神奇QVarient
语法基础(变量、输入输出、表达式与顺序语句)
OpenGL 工作原理
虚拟内存原理与技术
Beidou no. 3 short message terminal high slope in open-pit mine monitoring programme
lua learning
百日刷题计划 ———— DAY2
Use @Mapper to query the partition status of oracle and report an error
QT MV\MVC结构
Turn: Charles Handy: Who you are is more important than what you do
腾讯云【Hiflow】新时代自动化工具
QT: The Magical QVarient
线上MySQL的自增id用尽怎么办?
2022-08-04: Input: deduplicated array arr, the numbers in it only contain 0~9.limit, a number.Return: The maximum number that can be spelled out with arr if the requirement is smaller than limit.from
Gantt chart is here, project management artifact, template is used directly
Solve the problem of port occupancy Port xxxx was already in use