ASP.NET Core快速入门

一天之内从ASP.NET 跨越到ASP.NET Core

默认教学计划
2754人加入学习
(72人评价)
价格 ¥128.00
教学计划

声音太难听了。。。。

[展开全文]

啊撒范德萨分

[展开全文]

如果curl没有反应,需要在Program.cs文件的Main方法中加入如下代码
var host = new WebHostBuilder()
.UseUrls("http://localhost:5001")
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();

nginx绑定端口操作
vi /etc/nginx/nginx.conf

server {
        listen 80;
        

        location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

}

[展开全文]

不能ping外网
vi /etc/sysconfig/network-scripts/ifcfg-ens33      ---将ONBOOT="no"改成"yes"

解决ifconfig不能使用
yum install net-tools


下面开始进行安装nginx
yum -y update

yum install epel-release

yum install nginx       

=============================start 如果上一步报错“yum doesn't have enough cached data to continue.”则执行下面操作==============
1、将/etc/yum.repos.d/epel.repo中的mirrorlist改为baseurl
[root@ec-cache ~]# /usr/bin/vi /etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

2、/etc/resolv.conf文件中增加nameserver 144.144.144.144
[root@ec-cache ~]# vi /etc/resolv.conf

# Generated by NetworkManager
nameserver 192.168.1.2
nameserver 144.144.144.144

============================== end ============================================

systemctl start nginx
systemctl enable nginx
systemctl status nginx


firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload

[展开全文]

下面安装asp.net core
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install dotnet-sdk-2.2

 

 

新建一个webapi项目,但是5000端口还未打开,通过下面命令检验是否已经通了

curl http://localhost:5000/api/values

[展开全文]

配置文件绑定类

[展开全文]

1、查看指令
dotnet new mvc --help

其中:
-au|--auth                      The type of authentication to use
            Individual       - Individual authentication

-uld|--use-local-db        Whether to use LocalDB instead of SQLite. 
                                      This option only applies if --auth Individual or --auth IndividualB2C is specified.
                                      bool - Optional

                                      默认值: false/(*) true

2、创建一个MVC项目
①dotnet new mvc -au Individual -uld --name IdentitySample
②用VS Code打开创建的MVC项目文件夹

3、修改代码,并创建数据库
①修改appsettings.json的"DefaultConnection"连接字符串:"Server=."
然后初始化数据库:dotnet ef database update

②在Models文件夹下,分别创建ApplicationUser、ApplicationRole类
===================ApplicationUser.cs======================
using Microsoft.AspNetCore.Identity;

namespace IdentitySample.Models
{
    public class ApplicationUser:IdentityUser<int>
    {
        
    }
}
===================ApplicationRole.cs======================
using Microsoft.AspNetCore.Identity;

namespace IdentitySample.Models
{
    public class ApplicationRole:IdentityRole<int>
    {
        
    }
}

③在Data文件夹下找到ApplicationDbContext类,修改下代码:
将"public class ApplicationDbContext : IdentityDbContext"
改成"public class ApplicationDbContext : IdentityDbContext<ApplicationUser,ApplicationRole,int>"

④ConfigureServices方法中将
"services.AddDefaultIdentity<IdentityUser>()"
改成:"services.AddDefaultIdentity<ApplicationUser>()"
或者改成:"services.AddIdentity<ApplicationUser,ApplicationRole>()"

⑤修改Shared文件夹下的_LoginPartial.cshtml文件(坑爹的问题,没发现这里还有IdentiyUser要改,以后这种问题,直接用SublimeText搜索解决),

    @inject SignInManager<IdentityUser> SignInManager
    @inject UserManager<IdentityUser> UserManager
改成:
    @inject SignInManager<ApplicationUser> SignInManager
    @inject UserManager<ApplicationUser> UserManager


4、在ApplicationUser类中新增一个属性:Address1
①dotnet ef migrations add AddColumn_Address1
PS:有问题删migrations文件,还不行删数据库重来
①dotnet ef database update

5、在ApplicationUser类中新增一个属性:Address2
①dotnet ef migrations add AddColumn_Address2
PS:有问题删migrations文件,还不行删数据库重来
①dotnet ef database update

6.1、移除掉AddColumn_Address2,回滚到AddColumn_Address1状态【不是很推荐这种,除非确定是要回滚到某一个版本】
①dotnet ef database update AddColumn_Address1
执行完后去数据库看下,Address2字段已经被移除掉了
②但是项目中的migrations没有被移除,所以我们要手动移除掉
dotnet ef migrations remove

6.2、删除ApplicationUser类的Address1属性,同时同步到数据库【推荐这种】
①删掉ApplicationUser类的Address1属性
②dotnet ef migrations add RemoveAddress1
③dotnet ef database update

7、生成sql脚本命令(生产环境用的)
dotnet ef migrations script

[展开全文]

用的core 2.2版本,跟着老师代码敲得,最后用postman访问时提示404 然后是415,记录下解决过程

[展开全文]

现在VSCode使用watcher工具不需要在csproj文件的ItemGroup节点下添加这段代码,默认自带了,直接dotnet watch run即可

<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0"/>

[展开全文]

cd /etc/nginx

vi nainx

 

[展开全文]

dotnet publish -o d:/ 发布

iis 部署.net core,需要安装AspNetCoreModule

[展开全文]

ASP.NET CORE HTTP 处理过程

 

url -->httprequest-->server-->

[展开全文]

1.什么是依赖?

2.显示依赖与隐式依赖

3.依赖倒置原则

[展开全文]

必须安装:

microsoft.EntityFrameworkCore.Tools

dotnet ef migrations add VSInit

dotnet ef database update

[展开全文]

全面理解 ASP.NET Core 依赖注入

 

https://www.cnblogs.com/jesse2013/p/di-in-aspnetcore.html

[展开全文]
VicHuang · 2018-12-05 · 介绍 0
  1. donet --help
  2. dotnet new --help
  3. dotnet new mvc
  4. dotnet run
[展开全文]

dotnet new console

 

[展开全文]

授课教师

程序员

课程特色

视频(48)
图文(2)