【发布时间】:2012-08-10 20:28:26
【问题描述】:
在 asp.net mvc 3 中,我有一个具有 ssl 证书的站点,并且在 https 中运行得很好。唯一暴露的页面是登录页面。无论出于何种原因,它都不会在 https 中加载。这是我的相关代码(如果我遗漏了一些内容,将根据要求发布更多内容)。
web.config
<compilation debug="false" targetFramework="4.0">
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" requireSSL="true"/>
</authentication>
global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);
}
帐户控制人
#if !DEBUG
[RequireHttps]
#endif
public class AccountController : Controller
{
public ActionResult LogOn()
{
return View();
}
}
登录视图加载时,它不在 Https 中。我错过了什么?
【问题讨论】:
-
愚蠢的问题我知道,但你是在调试模式下运行吗?
-
@JohnH - :) 不(或者至少我相当肯定不是),看到 web.config 中包含的行了吗?
<compilation debug="false" targetFramework="4.0"> -
啊,是的,对不起,我错过了。 :)
-
@TravisJ - web.config 条目与编译站点时定义的 DEBUG 符号无关。这是在 Visual Studio 的构建目标设置中设置的。
-
@MystereMan - 啊,你是对的!为了使#Debug 在发布中为假,我应该编辑什么?
标签: asp.net-mvc-3 https requirehttps requiressl