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

}
相关推荐
完美火龙篇 四月的友18 小时前
通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core?
.net·.netcore
时代的狂16 天前
如何理解 C# 的 async 和 await
c#·.netcore·async·await
尼米棕熊18 天前
.NET CORE认证模块-注册方案与请求认证探究
.netcore
鸠摩智首席音效师2 个月前
如何在 macOS 上安装 .NET Core ?
macos·.netcore
宝桥南山2 个月前
Microsoft Agent Framework(MAF) - 如何将workflow或者A2A client转换成一个AI Agent
microsoft·ai·微软·aigc·.net·.netcore
滴滴答答哒2 个月前
.NET Core 基于 AOP + Polly 实现数据库死锁自动重试
数据库·.netcore·sqlsugar
.NET修仙日记2 个月前
.NET EFCore批量插入性能优化实战:30秒 → 0.5秒
性能优化·c#·.net·.netcore·微软技术·efcore·踩坑实录
Kimhill张2 个月前
.net core8 WPF 依赖注入(DI)
wpf·.netcore
wangl_922 个月前
C# / .NET 在工业环境中的优势
开发语言·c#·.net·.netcore·.net core·visual studio
豆豆3 个月前
信创环境下CMS国产化适配实践:以.NET Core路线为例的技术验证
.netcore·cms·信创·国产化·建站系统·内容管理系统·网站管理系统