【问题标题】:Url Rewrite for hosted application on IISIIS 上托管应用程序的 URL 重写
【发布时间】:2020-02-17 04:05:10
【问题描述】:

我已经开发了 asp.net mvc core 3.0 web 应用程序并部署在 windows server 中。我想在 url 中隐藏控制器名称。

示例:

原始网址:www.example.com/test/authenticate/login

预期网址:www.example.com/test/login

我不确定是通过实现它的代码还是 IIS。

startup.cs 路由代码。

app.UseEndpoints(endpoints =>
{
       endpoints.MapControllerRoute(
           name: "default",
           pattern: "{controller=Home}/{action=Index}/{id?}");

});

【问题讨论】:

标签: asp.net-mvc-4 asp.net-core iis-express asp.net-core-3.0 asp.net-core-3.1


【解决方案1】:

使用属性路由:

[Route("/")]
public class AuthenticateController : ControllerBase
{
    [HttpGet("login")]
    public IActionResult Get()
    {
        return Ok("Ok");
    }
}

【讨论】:

  • 如果我没有在控制器上添加路由,它就可以工作。你能解释一下[Route("/")]吗?
  • AuthenticateController.Get() 操作将针对 URL 路径(root+Action 路由)/login 执行
猜你喜欢
  • 1970-01-01
  • 2019-11-13
  • 2014-05-06
  • 2015-02-24
  • 1970-01-01
  • 2018-01-15
  • 2014-10-14
  • 2021-06-06
  • 1970-01-01
相关资源
最近更新 更多