用.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; }
    }

}
相关推荐
MoFe11 天前
【.net core】【RabbitMq】rabbitmq在.net core中的简单使用
分布式·rabbitmq·.netcore
van久2 天前
Day15:EF Core 入门 + CodeFirst(就业核心版)
.netcore
叫我黎大侠2 天前
.NET 实战:调用千问视觉模型实现 OCR(车票识别完整教程)
阿里云·ai·c#·ocr·asp.net·.net·.netcore
van久2 天前
Day15-4:【日志】中间件和过滤器 的对比选择
.netcore
van久3 天前
Day14: 搭建企业标准的DDD 简洁版四层架构
架构·.netcore
van久3 天前
ADay15-1: 安装 EF Core 包 到 对应DDD(领域驱动设计)四层架构‌
.netcore
时光追逐者4 天前
C#/.NET/.NET Core技术前沿周刊 | 第 69 期(2026年4.01-4.12)
c#·.net·.netcore
willhuo6 天前
基于Playwright的抖音网页自动化浏览器项目使用指南
爬虫·c#·.netcore·webview
csdn_aspnet7 天前
在 .NET Core 8 中实现 CORS
.netcore·跨域·cors·.net8
csdn_aspnet8 天前
在 ASP.NET Core (WebAPI) 中启用 CORS
后端·asp.net·.netcore