当前位置:网站首页>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>
运行结果如下:
边栏推荐
- In 2022, you still can't "low code"?Data science can also play with Low-Code!
- word column notes
- Matlab drawing 3
- leetcode - a subtree of another tree
- 论治理与创新,2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满落幕
- nodeJs--encapsulate routing
- 程序员的七夕浪漫时刻
- How to transfer a single node of Youxuan database to a cluster
- 语法基础(变量、输入输出、表达式与顺序语句完成情况)
- leetcode 15
猜你喜欢

Cloud Native (32) | Introduction to Platform Storage System in Kubernetes

Go 微服务开发框架 DMicro 的设计思路

The 20th day of the special assault version of the sword offer

【 2 】 OpenCV image processing: basic knowledge of OpenCV

Regular expression to match a certain string in the middle

VSCode Change Default Terminal 如何修改vscode的默认terminal

Details such as compiling pretreatment

Gantt chart is here, project management artifact, template is used directly

mysql没法Execute 大拿们求解

正则表达式,匹配中间的某一段字符串
随机推荐
Native js realizes the effect of selecting and canceling all the multi-select boxes
[深入研究4G/5G/6G专题-51]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-11-高可靠性技术-2-链路自适应增强(根据无线链路状态动态选择高可靠性MCS)
Hash table lookup (hash table)
undo问题
627. 变更性别
Note that Weifang generally needs to pay attention to issuing invoices
使用二维码传输文件的小工具 - QFileTrans 1.2.0.1
leetcode 15
数据增强Mixup原理与代码解读
Chinese characters to Pinyin
22-07-31周总结
QT MV\MVC structure
Flink 1.15.1 Cluster Construction (StandaloneSession)
How to transfer a single node of Youxuan database to a cluster
QT语言文件制作
Principle and Technology of Virtual Memory
J9 Digital Currency: What is the creator economy of web3?
汉字转拼音
Programmer's Tanabata Romantic Moment
DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)