【问题标题】:How do I set the protocol when using RedirectToAction in asp.net MVC?在 asp.net MVC 中使用 RedirectToAction 时如何设置协议?
【发布时间】:2009-09-29 14:27:31
【问题描述】:

如何调用 RedirectToAction 并在其中设置 http 或 https 目标?

编辑:我有网站,只有一页使用 https 协议,在我访问它后,asp.net mvc url 引擎开始在任何地方使用 https 协议。我必须使用 http 协议从该页面重定向,但默认情况下 mvc 使用 https 生成所有内容(页面上的操作链接,或使用重定向操作)。对不起我的英语=)

【问题讨论】:

  • 好奇,你想把它改成什么协议?

标签: asp.net-mvc


【解决方案1】:

使用 RequireSslAttribute(在 MVC 期货中)和 redirect=true 从 http 切换到 https,而不是尝试在 RedirectToAction 上设置协议。它只是更强大。

如果需要从 https 切换到 http 可以基于code of RequireSslAttribute 编写类似的属性。

【讨论】:

  • 当我使用它时出现错误 System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 '失败。
  • 您的主机似乎需要更多权限。
猜你喜欢
  • 2012-08-24
  • 1970-01-01
  • 2020-04-19
  • 2016-06-29
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多