Subj。我有一個ASP.NET 2 MVC工作者角色應用程序,與默認模板沒有多大差別。Windows Azure ASP.NET MVC角色在從HTTP重定向到HTTPS時行爲異常
當嘗試從HTTP重定向到HTTPS(當我們訪問由通常的RequireSSL屬性實現保護的Constroller時,會發生這種情況),我們會得到帶有「錯誤請求」消息的空白頁面。
的IntelliTrace表明這一點:
拋出該異常: 「文件 '/Views/Home/LogOnUserControl.aspx' 不存在」 (System.Web.HttpException)
調用堆棧是非常短的:
[External Code]
App_Web_vfahw7gz.dll!ASP.views_shared_site_master.__Render__control1(System.Web.UI.HtmlTextWriter __w = {unknown}, System.Web.UI.Control parameterContainer = {unknown})
[External Code]
App_Web_bsbqxr44.dll!ASP.views_home_index_aspx.ProcessRequest(System.Web.HttpContext context = {unknown})
[External Code]
用戶控制基準是通常的一個在/Views/Shared/Site.Master:
<div id="logindisplay">
<% Html.RenderPartial("LogOnUserControl"); %>
</div>
部分視圖LogOnUserControl.ashx位於Views/Shared(它是ASCX,而不是ASPX)。
當我們嘗試訪問網站頁面時,出現問題,需要身份驗證(FormsAuth)並重定向,因爲SSL。這些頁面通過RequireSSL屬性(Redirect == true)進行保護:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public sealed class RequireSslAttribute : FilterAttribute, IAuthorizationFilter
{
public bool Redirect { get; set; }
// Methods
public void OnAuthorization(AuthorizationContext filterContext)
{
// this get's messy, when we are running custom ports
// within the local dev fabric.
// hence we disable code in the debug
#if !DEBUG
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
if (filterContext.HttpContext.Request.IsSecureConnection)
return;
var canRedirect = string.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase);
if (canRedirect && Redirect)
{
var builder = new UriBuilder
{
Scheme = "https",
Host = filterContext.HttpContext.Request.Url.Host,
Path = filterContext.HttpContext.Request.RawUrl
};
filterContext.Result = new RedirectResult(builder.ToString());
}
else
{
throw new HttpException(0x193, "Access forbidden. The requested resource requires an SSL connection.");
}
#endif
}
}
顯然我們在RELEASE中爲這種情況編譯。
有沒有人有任何想法,什麼可能會導致這種奇怪的例外,以及如何擺脫它?
Mea culpa。當然,部分控制是ASCX。 – 2010-05-27 11:03:34
@RinatAbdullin如果這是答案,請將它標記爲:) – jamiebarrow 2012-04-05 06:34:19