question

robm-4957 avatar image
0 Votes"
robm-4957 asked YijingSun-MSFT commented

resource cannot be found issue

I have an entity framework app I am rehabilitating.
all the routes work just the one labeled details fails with the error below.



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: /Survey/Details/3

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


see image below the web page is there I cannot figure out how to debug this issue ?



125388-image.png


dotnet-aspnet-mvcdotnet-entity-framework
image.png (15.7 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You misunderstand the error and most likely MVC fundamentals. In MV,C the URL maps to an Action not a View. An action returns a View but the Action was not found.

Can you share the controller and route configuration?

0 Votes 0 ·

not sure if this is what you are asking about.


 public static class WebApiConfig
 {
      [EnableCors(origins: "https://www.comap.ca", headers: "*", methods: "*")]
     public static void Register(HttpConfiguration config)
     {
         //ENABLE CORS 
         config.EnableCors();

         config.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { id = RouteParameter.Optional }
         );
     }
 }



125756-image.png


0 Votes 0 ·
image.png (8.0 KiB)

I think this is what you are looking for.

125811-image.png






namespace SWAT
{
public static class WebApiConfig
{
[EnableCors(origins: "https://www.comap.ca", headers: "", methods: "")]
public static void Register(HttpConfiguration config)
{
//ENABLE CORS
config.EnableCors();

         config.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { id = RouteParameter.Optional }
         );
     }
 }

}

0 Votes 0 ·
image.png (8.0 KiB)
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered robm-4957 commented

Are you sure the namespace for the view Details is viable and namespaces in the view are viable? What about in JavaScript pathing used by the view is viable?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

java seems fine

@model SWAT.Models.tblSWATSurvey

@{ ViewBag.Title = "Details"; }

@section Scripts
{
<script src="@Url.Content("~/Scripts/jquery-2.1.0.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Highcharts-3.0.1/js/highcharts.js")" type="text/javascript"></script>


 @Scripts.Render("~/Content/session.js")

}

0 Votes 0 ·
YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered YijingSun-MSFT commented

Hi @robm-4957 ,
As far as I think, the most common problem of 404 is your request URL isn't match the route url.
If it is convenient, can you provide your routing configuration (RouteConfig)? By default,the url is like this

 "{controller}/{action}/{id}"

Through the information you provide, your request url is this:

 /User/Details/3

By the way,you should note wheather there are spelling errors.

Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ok posted below

0 Votes 0 ·
robm-4957 avatar image
0 Votes"
robm-4957 answered YijingSun-MSFT commented
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.Mvc;
 using System.Web.Routing;
    
 namespace SWAT
 {
     public class RouteConfig
     {
         public static void RegisterRoutes(RouteCollection routes)
         {
             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
             routes.MapRoute(
                  "CountriesList",
                  "Location/Countries/List/{regionID}",
                  new { controller = "Location", action = "CountryList", regionID = UrlParameter.Optional }
             );
    
             routes.MapRoute(
                  "SubnationsList",
                  "Location/Subnations/List/{countryID}",
                  new { controller = "Location", action = "SubnationList", countryID = UrlParameter.Optional }
             );
    
             routes.MapRoute(
                 name: "Default",
                 url: "{controller}/{action}/{id}",
                 //defaults: new { controller = "User", action = "Details", id = 191 }
                 defaults: new { controller = "User", action = "Details", id = 4 }
                 //defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
             );
         }
     }
 }
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @robm-4957 ,
Yes. According to your maproute, if you want to run the details page,it will run this:

 url: "{controller}/{action}/{id}"

And then you need to check your controller and action. In your images,I think your url need to like this:

  /User/Details/3

Best regards,
Yijing Sun

0 Votes 0 ·

thanks Sun but my problem arises with
/survey/details/3
not
/users/details/3

any suggestions?

0 Votes 0 ·

Hi @robm-4957 ,I think you don't understand my meanings. According to your controller file name and routemap in your posting, your route url need like this:url: "{controller}/{action}/{id}". Because you only give us the user controller,so I make a example of user. If your problem is survey, you must to check if you have the surveycontroller and details action. You also could break point the action and routemap to check if the codes run.

0 Votes 0 ·
Show more comments