Friday, February 25, 2011

The resource cannot be found error when using Dynamic Data.

Have you seen the error page shown below when you are developing a ASP.NET Dynamic Data application?

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
Requested URL: /DynamicData/PageTemplates/Edit.aspx


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

I thought my application was broken. In the end, it had nothing to do with my application. It has everything to do with how a ASP.NET Dynamic Data Domain Service Web Application is setup by default when press F5. By default the project is setup to open the Current Page as the start action. I noticed that if I have the Edit.aspx page selected in my Solution Explorer and then hit F5 I get the error above. Notice the url in your browser, it is something like this:

http://localhost:1440/DynamicData/PageTemplates/Edit.aspx

What I wanted and expected to happen was open the default page when I hit F5. The error is 100% correct. That page is not directly available since I am using Dynamic Data.

If I select my project instead and hit F5 I get the default page as expected and desired.

So, really all this is just because I didn’t realize what the default behavior was. The remedy is very simple. Right click on Default.aspx in the Solution Explorer and select Set as Start Page. This will change the Start Action to use a Specific Page (the Default.aspx in this case) instead of the Current Page.

If you are not sure what your project is set to you can right-click on your project in Solution Explorer and go to the Web tab. Here you will see Start Action. To have F5 always start the Default.aspx page make sure Default.aspx is in the Specific Page textbox.

Here is what it should look like:

image

9 comments:

Subu Swayam said...

Thank you so much. I spent 3 hours on this and almost gave up when I found your post. Thanks again

Brent V said...

I'm so glad it helped. I know I was in the boat. I just about gave up also.

Anonymous said...

thank you very much.........

Dano_Cuba said...

Excellent. This solve my problem. Thanks a lot!

Anonymous said...

Thank you for your efforts but i still get the same error
-- I used dynamic data to implement a Admin section in web site and but the Dynamic data files into folder
named with "Admin" whereas user will write http://www.siteAddress.com/Admin
to logon with Admin username and password then he can access the Admin tools
but i tried your solution and still get the same error any other ideas please .....????
Thanks :)

Brent V said...

Ahmed,

It sounds like you are saying you moved the DyanmicData directory to under the Admin directory you created. I don't think you can do that.

Best of luck.

Brent

Anonymous said...

Thanks for your replay
but when I moved the dynamic data with it's master page and it's contains , I see it work perfect on the localhost (my computer ) but I doesn't work properly on the server sometimes work and other get the mentioned error

if you think it's not right to move the dynamic data to Admin folder
, what could you advice me to implement Admin module with dynamic data in my website ?????

Thanks for your efforts :))

Brent V said...

Hi Ahmed,

If you can get it working under Admin is directory that is great. I have not had success doing so.

The DynamicData directory is not accessible via the url and instead uses paths defined in the Global.asax. Security can be done in a number of ways. The built in way is to add attributes to the methods in your DomainService (if you are using that). I didn't find that it was powerful enough and changed the DynamicData pages to do some custom authentication which works great.

Another option might be to have a separate app for admin type stuff. If you go that route you could take advantage of virtual directories in IIS and make your admin directory a virtual directory that points to your DyanmicData app.

I hope that helps.

Brent

Anonymous said...

Thanks a lot Eng.Brent
I will try hose solutions and reply
as soon as possible

thanks again fro your efforts :)