官网教程:https://docs.microsoft.com/zh-cn/aspnet/core/getting-started/?view=aspnetcore-3.0&tabs=windows

目录:

1.新建项目.NET CORE API

2.连接mysql(使用EF)

3.部署到windows-IIS

一 新建项目.NET CORE API

二 连接mysql(使用EF)

1.nuget:MySql.Data.EntityFrameworkCore        Microsoft.EntityFrameworkCore

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; namespace LibraryModel
{
[Table("School")]
public class SchoolModel
{
[Key]
public int Id { get; set; }
public string SchoolName { get; set; }
}
}
using LibraryModel;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace LibrarySystem.DB
{
public class LibraryContext : DbContext
{
public LibraryContext(DbContextOptions<LibraryContext> options) : base(options) { }
public DbSet<SchoolModel> School { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;
using LibrarySystem.DB;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; namespace LibrarySystem
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
} public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var conn = Configuration.GetSection("ConnectionString:Default").Value;
services.AddDbContext<LibraryContext>(options => options.UseMySQL(conn)); services.AddDbContext<TodoContext>(opt =>
opt.UseInMemoryDatabase("TodoList"));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
} app.UseHttpsRedirection();
app.UseMvc();
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionString": {
"Default": "server=127.0.0.1;userid=root;password=xxxx;port=3306;database=world;allowuservariables=True;"
},
"AllowedHosts": "*"
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LibraryModel;
using LibrarySystem.DB;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; namespace LibrarySystem.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SchoolController : ControllerBase
{
LibraryContext context;
public SchoolController(LibraryContext _context)
{
context = _context;
} [HttpGet]
[Route("Query")]
public dynamic Query(int id)
{
var data = context.School.FirstOrDefault(); return data;
} [HttpGet]
[Route("dosome")]
public dynamic Dosome()
{
return "";
} [HttpGet]
public dynamic GetList()
{
var data = context.School.ToList(); return data;
} }
}

2.浏览器访问:https://localhost:5001/api/school/query

三 部署到windows-IIS

官网教程:https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0

1.安装 .NET Core 托管捆绑包  dotnet-hosting-2.2.6-win.exe   ,地址:https://download.visualstudio.microsoft.com/download/pr/a9bb6d52-5f3f-4f95-90c2-084c499e4e33/eba3019b555bb9327079a0b1142cc5b2/dotnet-hosting-2.2.6-win.exe

2.项目发布。存在地址:D:\core-publish\publish

3.新建IIS网站

.net core 入门一的更多相关文章

  1. CentOS开发ASP.NET Core入门教程

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9891346.html 因为之前一直没怎么玩过CentOS,大多数时间都是使用Win10进行开发,然后程序 ...

  2. ASP.NET Core 入门教程 10、ASP.NET Core 日志记录(NLog)入门

    一.前言 1.本教程主要内容 ASP.NET Core + 内置日志组件记录控制台日志 ASP.NET Core + NLog 按天记录本地日志 ASP.NET Core + NLog 将日志按自定义 ...

  3. ASP.NET Core入门(一)

    大家好,很荣幸您点了开此篇文章,和我一起来学习ASP.NET Core,此篇文字为<ASP.NET Core入门>系列中的第一篇,本系列将以一个博客系统为例,从第一行代码,到系统发布上线( ...

  4. 【翻译】ASP.NET Core 入门

    ASP.NET Core 入门 原文地址:Introduction to ASP.NET Core         译文地址:asp.net core 简介           翻译:ganqiyin ...

  5. net Core 入门实战

    Asp.net Core 入门实战   Asp.Net Core 是开源,跨平台,模块化,快速而简单的Web框架. Asp.net Core官网的一个源码合集,方便一次性Clone 目录 快速入门 安 ...

  6. ASP.NET CORE 入门教程(附源码)

    ASP.NET CORE 入门教程 第一课 基本概念 基本概念 Asp.Net Core Mvc是.NET Core平台下的一种Web应用开发框架 符合Web应用特点 .NET Core跨平台解决方案 ...

  7. Docker系列之.NET Core入门(三)

    前言 在Docker生态系统中除了上一节所讲解的基本概念,还有其他专业术语,本文我们将一笔带过,同时会开始陆续进入到在.NET Core中使用Docker. 专业术语 Docker Engine(Do ...

  8. Asp.Net SignalR 使用记录 技术回炉重造-总纲 动态类型dynamic转换为特定类型T的方案 通过对象方法获取委托_C#反射获取委托_ .net core入门-跨域访问配置

    Asp.Net SignalR 使用记录   工作上遇到一个推送消息的功能的实现.本着面向百度编程的思想.网上百度了一大堆.主要的实现方式是原生的WebSocket,和SignalR,再次写一个关于A ...

  9. Orchard Core入门配方和主题

    包含Orchard Core入门配方和主题 可以通过两个不同的NuGet包使用Orchard Core. OrchardCore.Application.Cms.Core.Targets Orchar ...

  10. Asp.net Core 入门实战

    Asp.Net Core 是开源,跨平台,模块化,快速而简单的Web框架. Asp.net Core官网的一个合集,方便一次性Clone 目录 快速入门 安装 一个最小的应用 项目模板 路由 静态文件 ...

随机推荐

  1. CSS相对定位与绝对定位详解

    相对定位和绝对定位,不改变元素的大小形状,只改变元素的位置. 相对定位和绝对定位是通过position属性来控制的,position属性的值为下面几种: 值 描述 absolute 使元素绝对定位,相 ...

  2. Asp.Net MVC4 使用Unity 实现依赖注入

    项目创建参考 上一篇   <<Asp.Net  MVC5  使用Unity 实现依赖注入>>, 不同的是这里是 Unity.MVC4 装好后会出现 然后示例说在这里写对应关系 ...

  3. C#形参和实参、引用类型和值类型使用时的一个注意点。

    这是早上群里讨论的例子. static void main(string [] arg){ var p1=new Person{Name="张三"}; var p2=new Per ...

  4. android 拍照上传文件 原生定位

    最近公司需要一个android拍照上传和定位功能的的单一功能页面,一开始选择ionic cordova angular的一套H5框架,但是遇到和上传文件报错的问题,bug找了一天没找到原因,怀疑是io ...

  5. String成员函数

    string类提供的各种操作函数大致分为八类:构造器和析构器,大小和容量,元素存取,字符串比较,字符串修改,字符串接合,I/O操作以及搜索和查找. 函数名称 功能 构造函数 产生或复制字符串 析构函数 ...

  6. Spring Boot 中application.yml与bootstrap.yml的区别(转)

    yml与properties其实yml和properties文件是一样的原理,且一个项目上要么yml或者properties,二选一的存在. 推荐使用yml,更简洁. bootstrap与applic ...

  7. 【原】linux下部署web

    本机安装xshell.新建->主机处输入ip->确定,按提示输入用户名和密码 安装jdk(一般Linux上都已经安装好了) 安装tomcat. (1)在tomcat官网上下载tar.gz版 ...

  8. SQL进程死锁排查

    --进程执行状态 SELECT der.[session_id],der.[blocking_session_id], sp.lastwaittype,sp.hostname,sp.program_n ...

  9. HDU 6053 - TrickGCD | 2017 Multi-University Training Contest 2

    /* HDU 6053 - TrickGCD [ 莫比乌斯函数,筛法分块 ] | 2017 Multi-University Training Contest 2 题意: 给出数列 A[N],问满足: ...

  10. apache nginx 配置

    <VirtualHost *:80> ServerAdmin test@biuuu.com DocumentRoot E:\web\OTHER\test ServerName zjh.co ...