我有Asp.Net核心Web应用程序。使用以下控制器
[Produces("application/json")]
[Route("api/[controller]")]
public class TestController
{
[HttpGet]
[Route("firstroute")]
public async Task<IActionResult> FirstMethod()
{
...Some code...
}
[HttpGet]
[Route("secondroute")]
public async Task<IActionResult> SecondMethod()
{
...
SomeMethod(redirectLink)
...
}
}
我需要的是完全组装redirectLink到FirstMethod(它可能类似于:“http://localhost/api/test/firstroute”)。我不需要RedirectToAction,但确切地说Url是字符串。没有设法在this.Url或Microsoft.AspNetCore.Http.Extensions中找到任何合适的方法。
this.Request.GetDisplayUrl()以适当的格式返回结果,但仅针对被调用的方法。
您可以使用HttpContext.Request中的数据,如下所示
var Url = string.Format("{0}://{1}{2}", HttpContext.Request.Scheme,HttpContext.Request.Host,"/api/firstroute");
和重定向
return Redirect(Url);