[Bug]: ModuleApplication.DisableMvcResponseHeader / DnnMvcHandler.DisableMvcResponseHeader is used incorrectly.
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
There is a public static setting DnnMvcHandler.DisableMvcResponseHeader (that resembles the MvcHandler.DisableMvcResponseHeader from ASP.NET MVC), but its value is used improperly and not always taken into consideration.
Steps to reproduce?
- Set the value of
DnnMvcHandler.DisableMvcResponseHeadertotrueat startup (e.g. in a IDnnStartup implementation). - Access a page that has a module that renders using MVC.
- Look at the response headers from the page request,
X-AspNetMvc-Versionheader will be present.
Current Behavior
There is no way to completely hide the X-AspNetMvc-Version header.
The value of DnnMvcHandler.DisableMvcResponseHeader is passed in to the ModuleApplication.DisableMvcResponseHeader private static property through its ModuleApplication(RequestContext, bool disableMvcResponseHeader) constructor, called from the DnnMvcHandler.GetModuleRequestContext(HttpContextBase). This would mean that it will be taken into consideration when making a direct HTTP request to an MVC route (not tested).
At the same time the ModuleApplication() : this(null, disableMvcResponseHeader: false) constructor is used by MvcHostControl to instantiate ModuleApplication objects to be used when MVC modules are rendered as part of the page. Because the disableMvcResponseHeader is hardcoded to false the value of ModuleApplication.DisableMvcResponseHeader static field is constantly pinged between the two values (false from MvcHostControl and DnnMvcHandler.DisableMvcResponseHeader from DnnMvcHandler).
Expected Behavior
I would expect, similar to how MvcHandler.DisableMvcResponseHeader works in ASP.NET, that the value of DnnMvcHandler.DisableMvcResponseHeader is always taken into consideration throughout the MVC rendering stack.
Relevant log output
Anything else?
I see two options:
- Remove proprietary
DnnMvcHandler.DisableMvcResponseHeaderandModuleApplication.DisableMvcResponseHeaderproperties and useMvcHandler.DisableMvcResponseHeaderto decide. This would make DNN MVC be configured the same way standard ASP.NET MVC is. (Could be considered a breaking change if a 3rd party vendor tried to use the proprietary setting to disable the header). - Change
public ModuleApplication() : this(null, false) { }topublic ModuleApplication() : this(null, DnnMvcHandler.DisableMvcResponseHeader) { }to always default to whateverDnnMvcHandler.DisableMvcResponseHeaderis set to. I would also makeModuleApplication.DisableMvcResponseHeadernot static to avoid overwriting the value for other concurrent threads.
Let me know which of the solutions would you like more (or any other solution you can think of) and I will be able to create a PR with the fix.
Affected Versions
Current development branch (unreleased), 10.0.1 (latest v10 release)
What browsers are you seeing the problem on?
Chrome, Firefox, Safari, Microsoft Edge
Code of Conduct
- [x] I agree to follow this project's Code of Conduct