The referenced file '/Test/Test.ascx' is not allowed on this page.

I created a new sp2013 project and have an aspx page where I'm loading the user control called Test.ascx. The user control is created under /controltemplates under 15 hive.

The user control file structure is - /controltemplates/Test/Test.ascx

In my default.aspx I'm loading the user control with this path -

<%@ Register Src="~/Test/Test.ascx" TagName="TestUserControl" TagPrefix="Demo" %>

I get the error as : The referenced file '/Test/Test.ascx is not allowed on this page.

I added the folder under safe control in web.config and I did IIS reset but still get this error. Don't know what else can be done here
Who is Participating?
Rainer JeschorConnect With a Mentor Commented:
you should reference this:

<%@ Register Src="~/_CONTROLTEMPLATES/Test/Test.ascx" TagName="TestUserControl" TagPrefix="Demo" %>

Open in new window

(including the controltemplates virtual directory.

bujjigaduAuthor Commented:
I gave the complete path in web.config file but now I get parse error saying file does not exist in my aspx page where I'm loading the control

This is how I'm referencing in my aspx page to load user control

bujjigaduAuthor Commented:
If I remove _ infront of controltemplates then I get message that this page is not allowed error message.  controltemplates virtual folder created by default in visual studio when I add new user control.

Not sure how to reference in web.config and in my aspx page where I want to load the user control, please clarify
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.