问题
I recently got the following error in my web application.
The page 'ControlName.ascx' cannot use the user control 'OtherControl.ascx', because it is registered in web.config and lives in the same directory as the page.
Whilst I was able to fix the error by moving the control and registering it in the page I'm curious as to why this raises an error.
This is apparently by design as design as described here (3/4 down in yellow block) but my question is why? What problem might you face by registering the control in the Web.Config
and placing it the same directory?
回答1:
Maybe it is a matter of dynamic compilation. By default the "batch" attribute of the "compilation" element in your web.config is true. Something like this :
<compilation defaultLanguage="c#" debug="false" batch="true" targetFramework="4.0" />
With batch="true", whenever a control has to be compiled in a directory, the server compiles all controls (everything?) in its directory.
I would say that web.config declared controls are not compiled the same way as other controls (in another dll, another directory ?) So, mixing web.config declared controls and other controls in the same directory, some referencing the others would result in duplicate compilation and dll conflicts.
来源:https://stackoverflow.com/questions/10211635/the-page-y-ascx-cannot-use-the-user-control-x-ascx