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

}
相关推荐
夏霞2 天前
c# ASP.NET Core SignalR 客户端配置自动重连次数
c#·.netcore
BXS_null2 天前
windows、linux/ubuntu 系统运用.net core使用Selenium WebDriver实现自动化测试
linux·ubuntu·.netcore
切糕师学AI4 天前
.NET Core 如何使用 Quartz?
.netcore·quartz·作业调度
聪明努力的积极向上5 天前
【C#】System.Text.Encoding.Default 属性在framework和.netcore中的区别
开发语言·c#·.netcore
切糕师学AI6 天前
.NET Core Web + Vue 项目集成消息推送工具SignalR
vue.js·.netcore·signalr
万19996 天前
asp.net core webapi------3.AutoMapper的使用
c#·.netcore
dephixf8 天前
工业级部署指南:在西门子IOT2050(Debian 12)上搭建.NET 9.0环境与应用部署
物联网·.netcore·智能制造·边缘网关·西门子·iot 2050
睡前要喝豆奶粉8 天前
在.NET Core Web Api中使用JWT并配置UserContext获取用户信息
前端·.netcore
睡前要喝豆奶粉8 天前
在.NET Core Web Api中使用阿里云OSS
阿里云·c#·.netcore
周杰伦fans9 天前
.NET Core WebAPI 中 HTTP 请求方法详解:从新手到精通
网络协议·http·.netcore