如何使用Url.Action& lt; tController& gt;强制使用http或https [英] How to force http or https with Url.Action<tController>

查看:62
本文介绍了如何使用Url.Action& lt; tController& gt;强制使用http或https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MvcContrib的强类型Url.Action方法在我的网站上完成所有的url生成.

I'm using the strongly typed Url.Action method from MvcContrib to do all of my url generation on my site.

例如:

Url.Action<CategoriesController>(c => c.List())

是否有一种方法可以强制此方法生成的URL使用http或https?现在,它似乎只是相对于当前页面创建URL.因此,例如,如果我在https页面上,即使我不希望这些页面安全,它也会使我所有的页眉和页脚链接都使用https.

Is there a way to force the urls generated by this method to use http or https? Right now it seems to just be creating urls relative to the current page. So, for example, if I'm on an https page it makes all my header and footer links use https even though I don't want those pages to be secure.

类似的东西:

Url.Action<CategoriesController>(c => c.List(), protocol: "https")

推荐答案

不幸的是,MvcContrib的操作< T>扩展程序不支持生成https URL.

Unfortunately MvcContrib's Action<T> extension doesn't support generating https URLs.

在内部,此方法从MvcFutures库调用Microsoft的LinkBuilder.BuildUrlFromExpression方法,此方法非常简单.它仅支持生成简单的相对链接,不支持普通的Url.Action方法中内置的许多功能,包括https和area.只要MvcContrib扩展在内部依赖此方法,它将不支持这些附加功能.

Internally, this method calls into Microsoft's LinkBuilder.BuildUrlFromExpression method from the MvcFutures library which is very simplistic. It only supports generating simple relative links and doesn't support many of the features build into the normal Url.Action method including https and areas. As long as the MvcContrib extensions rely on this method internally, it won't support these additional features.

如果您想利用这些功能,最好还是坚持使用Mvc的常规Url.Action.

You'd be better off sticking with Mvc's normal Url.Action if you want to take advantage of these features.

这篇关于如何使用Url.Action&amp; lt; tController&amp; gt;强制使用http或https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆