获取控制器和操作的完全限定URL?

时间:2021-09-06 20:24:50

What's the correct way to get the full url (including protocol and domain) for a controller and action? I need this to be able to send links to pages via email.

获取控制器和操作的完整URL(包括协议和域)的正确方法是什么?我需要这个能够通过电子邮件发送链接到页面。

I was hoping to just use Url.Action() and concatenate it onto the current server hostname from Request.Url. However, it seems that Url.Action is context sensitive and so will not show the full path if you are already within the same controller.

我希望只使用Url.Action()并将其连接到Request.Url的当前服务器主机名。但是,似乎Url.Action是上下文敏感的,因此如果您已经在同一个控制器中,则不会显示完整路径。

Any ideas?

Thanks

James

1 个解决方案

#1


9  

There are overloads of Url.Action() that take the hostname, protocol, etc. Calling one of these overloads will generate a fully-qualified URL suitable for emailing.

Url.Action()的重载采用主机名,协议等。调用其中一个重载将生成适合于通过电子邮件发送的完全限定的URL。

#1


9  

There are overloads of Url.Action() that take the hostname, protocol, etc. Calling one of these overloads will generate a fully-qualified URL suitable for emailing.

Url.Action()的重载采用主机名,协议等。调用其中一个重载将生成适合于通过电子邮件发送的完全限定的URL。