当前位置:网站首页>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>
运行结果如下:
边栏推荐
- 剑指offer专项突击版第20天
- tree table lookup
- The Tanabata copywriting you want has been sorted out for you!
- 沃谈小知识 |“远程透传”那点事儿
- Cloud Native (32) | Introduction to Platform Storage System in Kubernetes
- Error: Not a signal or slot declaration
- Compressed storage of special matrices
- J9 Digital Currency: What is the creator economy of web3?
- 02 [Development Server Resource Module]
- 剑指Offer--找出数组中重复的数字(三种解法)
猜你喜欢
Simple description of linked list and simple implementation of code
QT MV\MVC structure
Question about #sql shell#, how to solve it?
Everyone in China said data, you need to focus on core characteristic is what?
Common hardware delays
How Jin Cang database correctness verification platform installation file
A small tool to transfer files using QR code - QFileTrans 1.2.0.1
mysql can't Execute, please solve it
数据增强Mixup原理与代码解读
word分栏小记
随机推荐
[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?
CPDA|How Operators Learn Data Analysis (SQL) from Negative Foundations
One hundred - day plan -- -- DAY2 brush
A small tool to transfer files using QR code - QFileTrans 1.2.0.1
Chinese characters to Pinyin
数据增强Mixup原理与代码解读
线上MySQL的自增id用尽怎么办?
Solve the problem of port occupancy Port xxxx was already in use
Programmer's Tanabata Romantic Moment
Cybersecurity and the Metaverse: Identifying Weak Links
论治理与创新,2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满落幕
leetcode - symmetric binary tree
北斗三号短报文终端露天矿山高边坡监测方案
C student management system Find student nodes based on student ID
Note that Weifang generally needs to pay attention to issuing invoices
QT MV\MVC结构
开源协议说明LGPL
OpenGL 工作原理
The design idea of DMicro, the Go microservice development framework
word分栏小记