The relative virtual path MyUserControl.ascx is not allowed here error in Web.Config

By | November 25, 2008

Problem

I am trying to add a user control in Web.Config file as below,

{codecitation style=”brush: xml; gutter:false”}
<controls>

<add tagPrefix=”MyControl” tagName=”MyUserControl” src=”MyUserControl.ascx”/>

</controls>

{/codecitation}

It gives me following error,

Configuration Error: The relative virtual path ‘MyUserControl.ascx’ is not allowed here.

Solution

To resolve this issue, move your WebUserControl from root directory to a sub directory. For example in my case, I would copy MyUserControl.ascx to sub folder “Controls”. So my Web.Config entry should look like below.

{codecitation style=”brush: xml;gutter:false”}
<controls>
<add tagPrefix=”MyControl” tagName=”MyUserControl” src= “~/Controls/MyUserControl.ascx”/>
</controls>
{/codecitation}

Notice how value of src parameter is changed.

~ indicates relative path from root folder.
This is one of the limitation of ASP.Net application. It does not allow you to register user control in Web.Config file unless it’s in a subfolder.

{kunena_discuss:24}

Leave a Reply

Your email address will not be published. Required fields are marked *