用.net core简易搭建webapi托管到IIS

1、从官网下载.NET Core 托管捆绑包

https://learn.microsoft.com/zh-cn/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-8.0\&tabs=visual-studio

2、新建ASP.NET Core WEB API项目


新建控制器TestController并生成GetInfo方法

3、发布

  1. 目标路径选择
    2)显示所有设置

    4、搜索IIS

    4、postman测试,这里端口使用8000

利用post传递Json数据

client code

复制代码
 string url = "http://localhost:8000/test/PostGetName.action";
 
 Tian tian = new Tian();
 tian.Name = "xiaobai";


 string postjson=Lan2Json.Convert2Json<Tian>(tian);

 string res=   Lan2Mes.PostJson(url, postjson);
 Debug.WriteLine("post back===>"+res);




服务器端代码
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace webapi.Controllers
{
    [Route("test")]
    [ApiController]
    public class TestController : ControllerBase
    {
        [HttpGet]
        public string GetInfo() { return "hello mengtianwxs!"; }


        [HttpPost("PostGetName.action")]
        public string Def([FromBody] Person name)
        {
            return $"姓名 {name.Name}";
        }

    }


    public class Person
    {
        public string Name { get; set; }
    }

}
相关推荐
van久2 天前
.Net Core 学习:Razor Pages中 HTML 表头字段的两种写法对比
学习·html·.netcore
武藤一雄2 天前
C# 万字拆解线程间通讯?
后端·微软·c#·.net·.netcore·多线程
武藤一雄4 天前
.NET中到底什么是SignalR (持续更新)
后端·微软·c#·asp.net·.net·.netcore·signalr
by__csdn4 天前
第二章 (.NET Core环境搭建)第二节( Visual Studio Code)
ide·vscode·c#·vue·asp.net·.net·.netcore
by__csdn4 天前
第二章 (.NET Core环境搭建)第三节( Visual Studio for Mac)
ide·kubernetes·c#·asp.net·.net·.netcore·visual studio
武藤一雄5 天前
C#:进程/线程/多线程/AppDomain详解
后端·微软·c#·asp.net·.net·wpf·.netcore
武藤一雄5 天前
C#:Linq大赏
windows·后端·microsoft·c#·.net·.netcore·linq
by__csdn6 天前
第一章 (ASP.NET Core入门)第三节( 认识.NET Standard)
后端·c#·asp.net·.net·.netcore·f#·vb.net
by__csdn6 天前
第一章 (ASP.NET Core入门)第一节( 认识.NET Core)
后端·c#·asp.net·.net·.netcore·f#·vb.net
by__csdn6 天前
第一章 (ASP.NET Core入门)第二节( 认识ASP.NET Core)
数据库·后端·c#·asp.net·.net·.netcore·f#