Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientDependency does not render on error.cshtml pages #162

Open
joshuahysong opened this issue Mar 8, 2019 · 1 comment
Open

ClientDependency does not render on error.cshtml pages #162

joshuahysong opened this issue Mar 8, 2019 · 1 comment

Comments

@joshuahysong
Copy link

Using ClientDependency to render CSS and JS files on a layout which is then used by an error.cshtml razor view does not render the css or js.

This error view is triggered via Application_Error call to an errors controller. The resulting DOM contains <!--[Css:Name="StandardRenderer"]//--> where the css statements would normally appear.

If you navigate directly to the error view then css/js files are loaded without issue. Only when the view is served via Application_Error does this issue occur.

The following is the code used to call the controller method

var exception = Server.GetLastError();
LogHelper.WriteError($"{exception.Message} | {exception.StackTrace} | {exception.InnerException?.Message} | {exception.InnerException?.StackTrace}");
Server.ClearError();

var routeData = new RouteData();
routeData.Values.Add("controller", "Errors");
routeData.Values.Add("action", "Error");
routeData.Values.Add("exception", exception);
routeData.Values.Add("statusCode", exception.GetType() == typeof(HttpException) ? ((HttpException)exception).GetHttpCode() : 500);

Response.TrySkipIisCustomErrors = true;

IController controller = new Controllers.ErrorsController();
controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));

Response.End();

Using the CdfRazorViewEngine alleviates this issue, however when using this view engine then an error is thrown for any view that attempts to load a partial.

This error occurs on line 46 in PlaceholderPraser.cs. The SingeOrDefault call fails since there is more than one "StandardRender" in the output object.

This occurs regardless of the partial view having any clientdependency calls and with only a single @Html.RenderCssHere() and @Html.RenderJsHere() in the associated layout.

@Shazwazza Shazwazza added the bug label Mar 11, 2019
@Shazwazza
Copy link
Owner

Sounds like a bug to be fixed with the CdfRazorViewEngine approach. The normal approach uses an httpmodule to parse the results but if an error occurs, its certainly possible that the request filter no longer applies and maybe even a request .end is called.

I might suggest though that if an application error occurs, in some cases you'd have to assume that your entire application is down and cannot run any .NET code. I've seen this many time and that's why normally for error pages I use static html pages (no server side logic)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants