当前位置:网站首页>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>
运行结果如下:
边栏推荐
- Snapback - same tree
- VSCode Change Default Terminal 如何修改vscode的默认terminal
- 语法基础(变量、输入输出、表达式与顺序语句)
- 金仓数据库如何验证安装文件平台正确性
- HDU 1114: Piggy-Bank ← The Complete Knapsack Problem
- Matlab画图3
- C student management system head to add a student node
- Principle and Technology of Virtual Memory
- OpenGL 工作原理
- shell语句修改txt文件或者sh文件
猜你喜欢
随机推荐
沃谈小知识 |“远程透传”那点事儿
Question about #sql shell#, how to solve it?
语法基础(变量、输入输出、表达式与顺序语句)
Talking about data security governance and privacy computing
剑指offer专项突击版第20天
The design idea of DMicro, the Go microservice development framework
[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?
[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)
word column notes
1667. Fix names in tables
Images using redis cache Linux master-slave synchronization server hard drive full of moved to the new directory which points to be modified
[Storage] Dawning Storage DS800-G35 ISCSI maps each LUN to the server
程序员的七夕浪漫时刻
Multithreading (2)
甘特图来啦,项目管理神器,模板直接用
The linear table lookup
627. 变更性别
QT MV\MVC结构
人人都在说的数据中台,你需要关注的核心特点是什么?
Study Notes-----Left-biased Tree









