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

}
相关推荐
小先生8125 天前
.NET Core后台任务队列
.net·.netcore
MoFe15 天前
【.net core】【watercloud】动态数据转换为静态表格,或者表格数据返回需要后处理
.netcore
吹牛不交税10 天前
.netcore项目部署在ubuntu22.04虚拟机的docker中的过程记录
docker·容器·.netcore
weixin_4219947814 天前
基于 .NET 9.0 的高性能轻量级令牌桶限流服务
.net·.netcore·令牌桶
weixin_4219947814 天前
MVC 模式初探
mvc·.net·.netcore
weixin_4219947815 天前
互联网与 Web 应用简介
.net·.netcore
全栈小517 天前
【C#】合理使用DeepSeek相关AI应用为我们提供强有力的开发工具,在.net core 6.0框架下使用JsonNode动态解析json字符串,如何正确使用单问号和双问号做好空值处理
人工智能·c#·json·.netcore·deepseek
时光追逐者19 天前
C#/.NET/.NET Core优秀项目和框架2026年1月简报
c#·.net·.netcore
大尚来也21 天前
双库协同,各取所长:.NET Core 中 PostgreSQL 与 SQLite 的优雅融合实战
postgresql·sqlite·.netcore
吹牛不交税21 天前
admin.net-v2 框架使用笔记-netcore8.0/10.0版
vue.js·.netcore