Webapi gets the URL address of the request

visual studio 2022

framework .net 7

Get the url in the controller

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

Guess you like

Origin blog.csdn.net/easyboot/article/details/129951565