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

}
相关推荐
火一线3 小时前
【ASP .NET Core】ASP .NET Core介绍
服务器·游戏·.netcore
GISer_Qing3 小时前
ASP.NET Core 8.0学习笔记(二十七)——数据迁移:Migrations深入与其他迁移命令
数据库·c#·.netcore·entityframework
shepherd枸杞泡茶2 天前
第3章 3.3日志 .NET Core日志 NLog使用教程
c#·asp.net·.net·.netcore
csdn_aspnet2 天前
ASP.NET Core 简单文件上传
asp.net·.netcore
亦世凡华、3 天前
掌握.NET Core后端发布流程,如何部署后端应用?
经验分享·.netcore·docker部署·程序发布
contact973 天前
.NET Core中的五种过滤器详解
.netcore·过滤器
以为不会掉头发的詹同学3 天前
【 Avalonia UI 语言国际化 I18n】图文结合教学,保姆级教学,语言国际化就是这么简单(.Net C#)
开发语言·前端·c#·.netcore·用户界面
爱吃香蕉的阿豪6 天前
在c#中虚方法和抽象类的区别
深度学习·c#·.netcore
shepherd枸杞泡茶6 天前
第3章 .NETCore核心基础组件:3.1 .NET Core依赖注入
开发语言·c#·.net·.netcore
.NET快速开发框架6 天前
使用nvm管理node.js版本,方便vue2,vue3开发
vue·.netcore·常用工具·开发技术·rdif