官网教程: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. Hdu 1517 巴什博奕变形

    易知2-9为先手胜 继续递推下去 10-18 后手胜 再推发现19-162先手胜 即发现有9(9) 18(2*9) 162(9*2*9)..... #include<bits/stdc++.h& ...

  2. solr 数据库关联,表数据添加不进solr,一直indexing

    id没有映射,数据库表字段没有id,要把其中一字段映射为id

  3. 201871010105-曹玉中《面向对象程序设计(java)》第十七周学习总结

    201871010105-曹玉中<面向对象程序设计(java)>第十七周学习总结 项目 内容 这个作业属于哪个过程 https://www.cnblogs.com/nwnu-daizh/ ...

  4. 如何理解JS内的Truthy值和Falsy值

    跟据MDN的术语表解释如下: 在 JavaScript 中,Truthy (真值)指的是在 布尔值 上下文中转换后的值为真的值.所有值都是真值,除非它们被定义为 falsy (即除了 false,0, ...

  5. JQuery调用绑定click事件的3种写法

    第一种方式: $(document).ready(function(){ $("#clickme").click(function(){ alert("Hello Wor ...

  6. Codevs 1213 解的个数(exgcd)

    1213 解的个数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知整数x,y满足如下面的条件: ax+by+c=0 p< ...

  7. noi.ac #528 神树和排列

    题目链接:戳我 #include<iostream> #include<cstring> #include<cstdio> #include<algorith ...

  8. C与C++ 中 struct和typedef struct

    总体分两块 1 首先://注意在C和C++里不同在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可:St ...

  9. HR问“你目前有几个offer”,聪明人会怎么说?

    点击上方“程序员江湖”,选择“置顶或者星标” 你关注的就是我关心的!   一个朋友和我聊天,说起自己最近被虐的面试经历.他985毕业,工作3年,看中了一家月薪1.5万的工作,准备跳槽.虽然在北京不算高 ...

  10. PHP7 的部分新特性

    1. 运算符(NULL 合并运算符) $a = $_GET['a'] ?? 1; 它相当于: <php$a = isset($_GET['a']) ? $_GET['a'] : 1; 我们知道三 ...