On the ASP.NET Core 3.x (1) - About ASP.NET

This article addresses: https://www.cnblogs.com/oberon-zjt0806/p/12209930.html

What I was ASP.NET

ASP.NET is an open source web framework, created by Microsoft, for building modern web apps and services with .NET.
ASP.NET是Giant hard (Macrohard)Web application development framework for an open-source Microsoft (Microsoft) launched, using modern technology to build .NET Web applications and services.
- ASP.NET

II ASP.NET how do I get it

Now I want to use this thing, how do I install and deploy it? ?

II.1 use Visual Studio integrated development and installation

From the start of Visual Studio 2015, Visual Studio began using module installer ways to install. For example, you download a Visual Studio 2019, then the first time you run the installation program will launch called Visual Studio Installerthe installer like this:
Visual Studio Installer
Visual Studio Installer provides for the Visual Studio development installable modules. Of course, because our current goal is to use Visual Studio ASP.NET Web development, so we only need to check this on it:
Visual Studio Installer - ASP.NET
and then click OK to install directory to install ......

II.2 manual installation

Visual Studio too fat! ! I do not want to install that thing! ! And I want to use other development environment! !

好好好,VS确实太肥了,毕竟不是所有的电脑都能跑得动那么重型的IDE,事实上我自己的电脑运行VS都会经常犯卡(我到现在还记得用那个挨千刀的Xamarin开发Android的时候我的电脑被VS和Android Emulator联合蹂躏的惨痛)。
ASP.NET提供了不需要Visual Studio的安装方式。
既然是ASP.NET嘛,名字里都说了,人家是基于.NET的,所以安装.NET SDK x64/.NET SDK x32就可以了。
如果安装后,使用命令提示符(cmd)或Powershell输入(...>是提示符标记,不用输入)

...> dotnet

显示

Usage: dotnet [options]
Usage: dotnet [path-to-application]

Options:
  -h|--help         Display help.
  --info            Display .NET Core information.
  --list-sdks       Display the installed SDKs.
  --list-runtimes   Display the installed runtimes.

path-to-application:
  The path to an application .dll file to execute.

意味着安装完成。

III 项目构建

基本的环境已经安装完成,我们就要使用这个框架去创建我们自己的项目。

如果安装了Visual Studio安装,那么就会看到新建项目的时候能找到这样的一项:
Visual Studio - Create ASP.NET Project
就可以创建一个ASP.NET的项目了。当然根据需要也可以使用一些含有第三方开发工具的Web项目,例如Angular、React等

但是,如果没有使用Visual Studio安装,而是直接安装的.NET SDK,那么需要启动.NET来构建项目,cmd中输入:

...> dotnet new webApp -o MyASPWebApplication --no-https
...> cd MyASPWebApplication
.../MyASPWebApplication>

就可以创建一个名为MyASPWebApplication,当然这个东西可以换成你喜欢的名字。这里使用的dotnet指令的模式为:

dotnet new <template> -o <appdir> --no-https

dotnet new <template> = 通过dotnet使用<template>模板构建一个基于.NET的内容
-o <appdir> = 放置生成的输出内容(也就是构建的内容)位置,这里为appdir。
--no-https = 不使用HTTPS协议构建项目。

Which <template>is the template used by the project, there is used webApp, of course, when building other types of projects may also use other values. Here we can only use this.
Although the -omark is specified file in the project folder where the directive does not use -nthe name tag of the specified item, but the agreement does not specify dotnet -ndirectly -o specified directory under the name of the project.

Either way building projects include the following structure:

MyASPWebApplication/
├─obj/
│ └─/一些文件.../
├─Pages/
│ ├─Shared/
│ │ ├─_Layout.cshtml
│ │ └─_ValidationScriptsPartial.cshtml
│ ├─Error.cshtml
│ ├─Error.cshtml.cs
│ ├─Index.cshtml
│ ├─Index.cshtml.cs
│ ├─Privacy.cshtml
│ ├─Privacy.cshtml.cs
│ ├─_ViewImports.cshtml
│ └─_ViewStart.cshtml
├─Properties/
│ └─launchSettings.json
├─wwwroot/(empty)
├─appsettings.Development.json
├─appsettings.json
├─Program.cs
├─Startup.cs
└─MyASPWebApplication.csproj

Among them, Startup.csis the start of WebApp behavior, which contains all the configuration and settings. PagesIt contains items folder several sample Web pages, and MyASPWebApplication.csprojis the project organize your files, including the organization of the project and references to other libraries.
Of course, this *.csprojfile can also use other versions of Visual Studio C # or other IDE's open.

IV project run

Before you run an ASP.NET project, install IIS . Because Anyway, a Web application is usually run on a server, IIS can be an ordinary Windows computer built as a server.
IIS after the installation is complete, in Visual Studio to see the Run button becomes:
Visual Studio - Run ASP
click Visual Studio runs the page of the project in order to specify the current computer browser (and the following method is different, Visual Studio App designated port is running randomly from the subscriber port specified, but not necessarily 5000).
If there is no Visual Studio, then type in cmd:

.../MyASPWebApplication> dotnet run

Then use a browser to access: localhost:5000/you can see the following screen operation:
ASP - Run

Up to now, a simple ASP.NET project to build even if the end. About code modification andTo be continued...

Guess you like

Origin www.cnblogs.com/oberon-zjt0806/p/12209930.html