programing

ASP.Net MVC – 리소스를 찾을 수 없음 오류

nasanasas 2020. 12. 3. 07:58
반응형

ASP.Net MVC – 리소스를 찾을 수 없음 오류


저는 ASP.Net MVC를 완전히 처음 사용합니다. 방금 Visual Studio 2010에서 MVC3 프로젝트를 만들었습니다.보기 엔진은 면도기입니다. 방금 응용 프로그램을 실행했을 때 브라우저에서 적절한 결과를 얻었습니다. URL은 http : // localhost : 4163 / 입니다. 그런 다음 ~ \ Views \ Home 폴더의 Index.cshtml에 "시작 페이지로 설정"을 적용했습니다. 그런 다음 응용 프로그램을 실행하면 URL이 http : // localhost : 4148 / Views / Home / Index.cshtml이 되었고 리소스를 찾을 수 없다고 말했습니다. 수정하려면 어떻게해야합니까? URL 매핑은 어디에서 이루어 집니까?

Global.asax 파일 :

using System.Web.Mvc;
using System.Web.Routing;

namespace TEST
{

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
    }
 }

URL 매핑 또는 "라우팅"은 ASP.NET MVC 사이트의 루트에있는 Global.asax에서 처리합니다.

"시작 페이지로 설정"을 클릭하면 응용 프로그램 루트와 관련된 해당 파일을 찾도록 프로젝트 설정이 변경됩니다. 그러나 MVC의 기본 색인 페이지로 경로가 실제로 http://localhost:4163/Home/Index- 같은 읽기 뭔가 작품을 라우팅하는 방법에 대한 아이디어를 얻을 수 있습니다.

보기로 직접 이동하려고 시도했지만 실패한 프로젝트를 "수정"하려면 프로젝트를 마우스 오른쪽 단추로 Properties클릭하고 " Web"을 선택한 다음 " "탭을 클릭하고 " "을 선택 Specific Page하고 텍스트 상자를 비워 둡니다. 이제 디버그를 시작하면 홈 페이지로 다시 이동해야합니다. Global.asax의 RegisterRoutes 메서드에서 이유를 확인하려면 기본 경로 매개 변수를 확인하세요.


컨트롤러 폴더에 HomeController.cs 클래스를 생성했는지 확인하십시오.


내가 직면 한 비슷한 문제에서 내 Action에는 HTTP "POST"속성이 있지만 페이지를 열려고했습니다 (기본적으로 "GET").

그래서 저는 HTTP "GET"버전을 만들어야했습니다.


나도 같은 html-404 오류가 발생했습니다.

리소스를 찾을 수 없습니다. 설명 : HTTP 404. 찾고있는 리소스 (또는 해당 종속성 중 하나)가 제거되었거나 이름이 변경되었거나 일시적으로 사용할 수 없습니다. 다음 URL을 검토하고 철자가 올바른지 확인하십시오.

그러나 면밀히 조사한 결과 컨트롤러의 이름 Default1ControllerHomeController. 변경하고 앱을 디버깅했을 때 작동했습니다. 같은 문제가 있으면 도움이되기를 바랍니다.


asp.net mvc 응용 프로그램을 실행하려면 아래 단계를 따르십시오.

  • 컨트롤러 생성
    컨트롤러 폴더를 마우스 오른쪽 버튼으로 클릭하고 컨트롤러를 추가합니다. 참고-Controller 접미사를 제거하지 마십시오. ASP.NET MVC 규칙.
    컨트롤러에 "DemoController"로 이름을 지정하면 "DemoController"에 "Index"액션이있는 것을 볼 수 있습니다. "인덱스"는 컨트롤러를 만들 때 표시되는 기본 작업입니다.

  • 보기 생성
    "인덱스"작업 이름을 마우스 오른쪽 버튼으로 클릭하고 기본보기 이름 즉, "인덱스"를 유지하고 "추가"버튼을 클릭합니다.

  • 경로 설정
    Global.asax 파일을 열면 경로 의 기본 설정이 "홈"컨트롤러에 매핑되고 "인덱스"동작이 "데모"컨트롤러 및 "인덱스"동작으로 변경되는 것을 볼 수 있습니다. URL 매핑은 Global.asax 파일에 작성됩니다. Global.asax 파일을 열면 아래 설정이 표시됩니다.

    routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    

    다음으로 변경하십시오.

    routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Demo", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    

그리고 응용 프로그램을 실행하면 응용 프로그램이 작동하는 것을 볼 수 있습니다.


놀랍게도 컨트롤러에서 공개 키워드를 실수로 삭제했습니다 !

여기에 이미지 설명 입력

나는 이것이 다른 누구에게도 도움이되지 않을 것이라고 생각하지만 결코 알지 못합니다 ...


asp.net mvc에서 기본 페이지를 설정할 수 없습니다.
global.asax.cs로 이동하여 라우팅 정의를 확인합니다. 기본 경로는 Index 메서드 HomeController를 가리 킵니다.
asp.net mvc에 대한 짧은 영화를 보거나 프레임 워크에 매우 빠르게 익숙해 질 수있는 괴상한 저녁 튜토리얼 을 찾아 보는 것이 좋습니다 .

튜토리얼에 대한 최고의 답변이 이미이 질문에 대한 답변으로 제공되었다고 생각합니다.

ASP.NET MVC 빠른 자습서


asp.net mvc에서는 mvc보기가 웹 양식 페이지와 같이 독립적이지 않기 때문에 '시작 페이지로 설정'옵션을 사용할 수 없습니다. 모델을 표시하기위한 템플릿 파일입니다. 처리 http 모듈이 없습니다. 모든 웹 요청은 컨트롤러 작업을 통과해야하며 뷰를 직접 요청할 수 없습니다.


얼마 전에 VS 2012를 사용할 때 비슷한 문제가 발생했습니다. 빌드> 다시 빌드를 클릭하여 응용 프로그램을 다시 빌드하면 해결되었습니다.


IIS Express를 사용하는 경우. 동일한 가상 디렉터리를 사용하는 다른 프로젝트를 열었을 수 있습니다. 두 번째 솔루션을 열면 VS는 해당 IIS 디렉토리를 다른 위치로 다시 매핑합니다. 결과적으로 다른 문제에서는 작동하지 않습니다. 토픽 스타터와 같은 오류가 발생했습니다.

해결 방법 : VS Studio의 모든 인스턴스를 닫습니다. 작업중인 프로젝트로 VS를 열고 다시 빌드합니다.


여기에 이것을 추가하기 만하면됩니다. 홈 컨트롤러의 색인 페이지가 더 이상로드되지 않는 문제가있는 사람은 아직 시작 프로젝트를 설정하지 않았기 때문일 수 있습니다 . 앱을 시작하려는 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 시작 프로젝트로 설정하면됩니다.


(MVC 5) : RouteConfig.cs다음 routes과 같이 두 개를 포함하도록 변경 합니다 .

            routes.MapRoute(
            name: "DefaultWithLanguage",
            url: "{language}/{controller}/{action}/{id}",
            defaults: new { language = "fa", controller = "Home", action = "Index", id = UrlParameter.Optional },
            constraints: new {language= "[a-z]{2}"}
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { language = "fa", controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

따라서 경로의 언어 부분이 지정되지 않은 경우 정규식 "[a-z]{2}"일치하지 않는 컨트롤러 이름을 착각하지 않고 기본 언어를 대체하고 나머지 경로로 리디렉션합니다.


asp.net mvc 프로젝트의 시작 페이지는 "현재 페이지"기본값입니다. 서버 측 파일을 열고 프로젝트를 시작하기 만하면됩니다. 그런 식으로 mvc는 프로젝트의 홈 컨트롤러 인 기본 컨트롤러를 엽니 다.


프로젝트 속성 (프로젝트-> 프로젝트 속성) 내에서 시작 페이지를 변경할 수 있습니다. 웹 탭에서 specify page시작 페이지를 선택 하고 home/또는로 변경할 수 있습니다 home/index. 경로에 따라 적절한 페이지로 이동합니다. http : // localhost : 4148 / Views / Home / Index.cshtml 의 주소는 URL이 http : // localhost : 4148 / {controller 여야한다고 명시한 경로에 따라 처리되기 때문에 특별히 작동하지 않습니다 . } / {action} 및 선택적 / {id}.

라우팅에 대한 자세한 내용은 여기를 참조하십시오.


다음과 같이 브라우저 입력의 주소 표시 줄에 다음과 같이 입력합니다. ControllerName / ActionMethod는 주소 표시 줄에 ControllerName / ViewName을 입력하지 않습니다. http : // localhost : 55029 / test2 / getview cshtml 파일 코드 :

@{
Layout = null; 
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>MyView</title>
</head>
<body>
<div>            
</div>
</body>
</html>

및 cs 파일 코드 :

public ActionResult GetView()
{
return View("MyView");
}

위의 모든 해결책을 시도했지만 문제가 계속되면이 간단한 해결책을 사용하십시오. 링크 에서 페이스 북 디버거를 열고 페이지 URL을 입력 한 다음 새 스크랩 정보 가져 오기 버튼을 클릭합니다. 이것은 당신의 문제를 해결할 것입니다.

The reason behind (what I think) is that facebook api saves current state of the page and shows same from its own server. if you click share button while coding and your page actually is not uploaded then facebook api could not find that page on server and saves the page state as "resource not found". Now it will keep showing same message even after you upload the page. When you fetch page from facebook debugger, it resolve everything from scratch and saves current state of the page and then your share button starts working without any change in the coding.


I had the same sort of issue, except I was not using the name Index.cshtml for my View, I made it for example LandingPage.cshtml, my problem was that the ActionResult in my Controller was not the same name as my View Name(In this case my ActionResult was called Index()) - This is actually obvious and a silly mistake from my part, but im new to MVC, so I will fail with the basics here and there.

So in my case I needed to change my ActionResult to be the same name as my View : LandingPage.cshtml

    public ActionResult LandingPage()
    {
        ProjectDetailsViewModels PD = new ProjectDetailsViewModels();
        List<ProjectDetail> PDList = new List<ProjectDetail>();

        PDList = GetProductList();
        PD.Projectmodel = PDList;


        return View(PD);
    }

I am new to MVC, so perhaps this will help someone else who is new and struggling with the same thing I did.


For me the problem was caused by a namespace issue.

I had updated my project namespace in my web project classes from MyProject to MyProject.Web, but I had forgotten to update the Project Properties >> Default Namespace. Therefore when I added a new controller it was using the old namespace. All I had to do was correct the namespace in the new controller and it worked.


I had a controller named usersController , so I tried to create it the start page by changing default controller from Home to usersController like given below.

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "usersController", action = "Index", id = UrlParameter.Optional }
        );
    }

The solution was to change controller default value to users rather than usersController

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "users", action = "Index", id = UrlParameter.Optional }
        );
    }

Simple Solution using HomeController.cs:

Open HomeController.cs file under Controllers folder. Add the code:

public ActionResult Edit()
{
    return View();
}

Now, if you are using a different controller (not HomeController):

To see your View like this:

http://localhost:1234/xyz/MyView

In the xyzController.cs file, under Controllers folder,

다음과 같은 ActionResult 메서드를 추가해야합니다.

public ActionResult MyView()
{
    return View(myView); //pass in your view if you want.
}

내 모델 이름을 올바르게 참조하지 않았을 때도이 메시지를 받았습니다.

@using (Html.BeginForm ( "MyView", "MyModel", FormMethod.Get))


시작 페이지로 원하는보기를 마우스 오른쪽 버튼으로 클릭하여 문제를 해결했습니다. "찾고있는 리소스를 찾을 수 없습니다"라는 오류가 표시된 후 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 웹으로 이동하여 현재 페이지를 선택합니다. 그것은 문제를 해결할 것입니다

참고 URL : https://stackoverflow.com/questions/9293778/asp-net-mvc-resource-cannot-be-found-error

반응형