registering user controls in web.config, causes error if used in same directory...

T

Tim_Mac

Hi,
i have this in my web.config:
<pages validateRequest="false" >
<controls>
<add tagPrefix="uc1" src="/Whatever.ascx" tagName="Whatever"/>

i have this in Login.aspx:
<uc1:Whatever id="Blah" runat="server">

I get this error message:

Cannot use the user control '/Whatever.ascx', because it is registered in
web.config and lives in the same directory as the page.

this same message has been posted twice without answers on the forums at
www.asp.net
http://forums.asp.net/thread/1347796.aspx
http://forums.asp.net/thread/1253193.aspx

does anyone know what is going wrong?

i'm using a Web Application Project. the problem goes away when i move the
user control into a subdirectory and update the web.config reference etc.

thanks in advance
tim
 
Joined
Aug 29, 2006
Messages
8
Reaction score
0
Tim_Mac said:
<add tagPrefix="uc1" src="/Whatever.ascx" tagName="Whatever"/>

I haven't had a chance to test this out in a development environment, but a possible solution might be to change the above line to the following:

Code:
<add tagPrefix="uc1" src="~/Whatever.ascx" tagName="Whatever"/>

Notice the "~" at the beginning of the src attribute. Note: This will only work if Whatever.ascx is in the root directory of your site, if not you must prefix Whatever.acsx with the folder name it can be found in - e.g. "~/Folder1/SubFolder/Whatever.ascx".

I have had some weird dealings in the past where I have used a "/page.aspx" instead of a "~/page.aspx".

I will be interessted to find out if this fixed the problem.

Gary Francis
Software Developer
SSI Comuter Services Ltd.
Providing IT Support services for London
 
W

Walter Wang [MSFT]

Hi Tim,

This limitation is documented in following MSDN library:

http://msdn2.microsoft.com/en-us/library/system.web.configuration.tagprefixi
nfo.aspx

This is due to internal design consideration (performance). The common use
of this new feature is to have a directory containing a bunch of user
controls, and register them in config so that they are available in all
pages. Thank you for your understanding.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rhywun

The [controls] tag also doesn't work when used in a web.config file
that's in a subdirectory of the root directory, right?
 
Joined
Oct 27, 2008
Messages
1
Reaction score
0
I had a similar problem (ASP net 2.0) with controls placed at the root level.

I had several controls (none nested) the error was : " ...because it is registered in web.config and lives in the same directory as the page."

The final fix was to place the .ascx controls in a directory called Controls, then adjust the web.config to :

<pages>

<controls>
<add src="~/controls/stoc_top.ascx" tagPrefix="Stoc" tagName="HeadTop" />
<add src="~/controls/stoc_footer.ascx" tagPrefix="Stoc" tagName="Footer"/>


</controls>

</pages>


Note: the ~/controls/ pre-fix
 
Joined
Aug 4, 2010
Messages
1
Reaction score
0
Nested usercontrols

Nested usercontrols will however be problem as the same exception will be thrown...this can be fixed by adding the user control to the page with a different TagPrefix than in the web.config.

Web.config
<add tagPrefix="webConfigPrefix" src="~/Controls/MyUserControl.ascx" tagName="MyUserControl"/>

Page
<%@ Register Src="~/Controls/MyUserControl.ascx" TagName="MyUserControl" TagPrefix="pagePrefix" %>
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top