webapi获取请求的URL地址

visual studio 2022

framework .net 7

在controller中获取url

Url.ActionContext.HttpContext.Request.Host.Value; 

namespace LaserCleanTyre.Controllers
{   /// <summary>
    /// SignalR客户端
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class SignalRController : ControllerBase
    {
        /// <summary>
        /// 获取URL地址
        /// </summary>
        /// <returns></returns>
        [HttpGet(Name = "GetURL")]
        public string GetURL()
        {
            string s = Url.ActionContext.HttpContext.Request.Host.Value;
            return s;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/easyboot/article/details/129951565
今日推荐