This is posted here because it might be module related.
MVC 3+, Win7 (development) (IIS7 production)
Using VS2010 Local server my HttpModule for exception handling works fine. When going to IIS I get the yellow screen of death.
The example below is for MVC, but an extremely similar Module which worked for years for Asp.net applications is now failing the same way. It differed by instead of returning a view, returned an embedded aspx page.
So I tried messing with the web.config by using httpErrors and I tried messing with the response by adding:
TrySkipIisCustomErrors
privatestaticvoid LogUheToUI()
{
HttpContext ctx = HttpContext.Current;
HttpRequestWrapper req = newHttpRequestWrapper(ctx.Request);
Exception ex = ctx.Server.GetLastError();
ctx.Response.Clear();
if (ctx.CurrentHandler != null) // i.e. we are in the MVC handler
{
RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
ctrler c = newctrler();
ControllerContext cc = newControllerContext(rc, c);
ViewResult viewResult = newViewResult { ViewName = "Error" }; //This needs to be a view in the real app which will load the partial view from the dll.
viewResult.ViewBag.Title = FormatDisplayString("(ApplicationName) problem");
viewResult.ExecuteResult(cc);
// If ajax request we need to tell it that failure occured. // So we put in a 400 Status Code. Otherwise it would get this error page back as a success result.// This error page will be returned in the Error response. if (req.IsAjaxRequest())
rc.HttpContext.Response.StatusCode = 400;
ctx.Response.TrySkipIisCustomErrors = true;
ctx.Server.ClearError();
}
elseif (ex isHttpRequestValidationException) //this occurs before MVC handler
{
ctx.Response.Clear();
string resMsg = "<html><body><span style=\"font-size: 12pt; color: red\">"
+ "Your input contains text that is not allowed.<br />"
+ "Text provided cannot contain character combinations such as :"
+ "<ul><li><janedoe@lanl.gov></li><li>&#949;</li><li><Text</li></ul>"
+ "The application treats this as an attempt to enter a potentially malicious programming string that could be executed when a person browses a webpage. Please review your input and remove any entries that resemble the above."
+ "<br/>";
if (req.IsAjaxRequest()) //if ajax request we have to set the status code to an error code so that ajax does not view this response as success. On error a modal dialog will be shown with this response.
ctx.Response.StatusCode = 400;
else//if not ajax provide a javascript back button
resMsg = resMsg + "<br/><br/><input id=\"btnBack\" type=\"button\" value=\"Back\" onclick=\"history.back()\"/>";
resMsg = resMsg + "<br/></span></body></html>";
ctx.Response.Write(resMsg);
ctx.Response.TrySkipIisCustomErrors = true;
ctx.Response.Flush();
ctx.Server.ClearError();
ctx.Response.End();
}
}
Added an else just to write to response; No Change. However, it still works when local on Win 7 vs web server or win7 webserver but not on iis7.
I think it has something to do with:
ctrler c = newctrler();
ControllerContext cc = newControllerContext(rc, c);
ViewResult viewResult = newViewResult { ViewName = "Error" }; //This needs to be a view in the real app which will load the partial view from the dll.
Maybe the VirtualPathProviders work differently in iis7??? Or maybe the compilation is different and the embedded view can't be found?? I tried to post this question in another area but MS deleted it.
rtyhhn54
Member
25 Points
64 Posts
HttpModule for error handling fails in IIS7
May 21, 2012 10:34 PM|LINK
This is posted here because it might be module related.
MVC 3+, Win7 (development) (IIS7 production)
Using VS2010 Local server my HttpModule for exception handling works fine. When going to IIS I get the yellow screen of death.
The example below is for MVC, but an extremely similar Module which worked for years for Asp.net applications is now failing the same way. It differed by instead of returning a view, returned an embedded aspx page.
So I tried messing with the web.config by using httpErrors and I tried messing with the response by adding: TrySkipIisCustomErrors
I have an HttpModule with
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: HttpModule for error handling fails in IIS7
May 23, 2012 10:33 AM|LINK
may be this if and else if conditions are failing
try else condition and return something similar and check if that works
rtyhhn54
Member
25 Points
64 Posts
Re: HttpModule for error handling fails in IIS7
May 23, 2012 01:28 PM|LINK
Added an else just to write to response; No Change. However, it still works when local on Win 7 vs web server or win7 webserver but not on iis7.
I think it has something to do with: