在Controller中创建完整URL

时间:2018-12-14 20:55:25

标签: c# asp.net-mvc

这是基于对类似问题的答案here

我的代码如下:

string url = Url.Action("Details", "Home", new RouteValueDictionary(new { Area = "MyArea", id = Id }), HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Authority);

但是,生成的url包含如下所示的双端口号:

http://localhost:54383:54383/MyArea/Home/Details/1

网址应为:

http://localhost:54383/MyArea/Home/Details/1

1 个答案:

答案 0 :(得分:3)

尝试一下就可以了

 string url = Url.Action("Details", "Home", new { Area = "MyArea", id = Id }, HttpContext.Request.Url.Scheme);