如何强制HTTP或HTTPS与Url.Action< tController> [英] How to force http or https with Url.Action<tController>

查看:317
本文介绍了如何强制HTTP或HTTPS与Url.Action< tController>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是从MvcContrib强类型Url.Action的方法做我所有的URL生成的我的网站上。

例如:

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

有没有办法强制通过这种方法生成的使用HTTP或HTTPS的网址?现在,它似乎只是要创建相对于当前网页网址。因此,举例来说,如果我是一个HTTPS页面上它使所有我的页眉和页脚链接使用https,即使我不希望这些网页是安全的。

是这样的:

  Url.Action< CategoriesController>(C => c.List(),协议:https开头)


解决方案

不幸的是MvcContrib的动作< T>扩展不支持产生https网址。

在内部,这个方法调用到从MvcFutures库,这是非常简单的微软LinkBuilder.BuildUrlFromEx pression方法。它仅支持生成简单的相对链接和不支持的许多功能建设进入正常Url.Action方法,包括HTTPS和地区。只要MvcContrib扩展依靠这种方法在内部,它不支持这些附加功能。

如果你想利用这些功能你会更好用MVC的正常Url.Action坚持。

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

For example:

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

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.

Something like:

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

解决方案

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

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.

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

这篇关于如何强制HTTP或HTTPS与Url.Action&LT; tController&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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