IT박스

route.IgnoreRoute (“{resource} .axd / {* pathInfo}”) 란 무엇입니까?

itboxs 2020. 9. 8. 07:46
반응형

route.IgnoreRoute (“{resource} .axd / {* pathInfo}”) 란 무엇입니까?


뭐가 routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

프로젝트에서 .axd 파일을 찾을 수 없습니다.이 경로 규칙을 제거 할 수 있습니까?


.axd 파일은 물리적으로 존재하지 않습니다. ASP.NET은 내부적으로 .axd 확장명 (ScriptResource.axd 및 WebResource.axd)이있는 URL을 사용하며 HttpHandler에 의해 처리됩니다.

따라서 ASP.NET MVC가 전용 HttpHandler가 요청을 처리하도록하는 대신 요청을 처리하지 못하도록이 규칙을 유지해야합니다.


몇 가지 배경

이 파일을 여는 경우 :

%WINDIR%\Microsoft.NET\Framework\version\Config\Web.config

파일에서 찾을 수 있습니다.

<add path="WebResource.axd"
     verb="GET"
     type="System.Web.Handlers.AssemblyResourceLoader"
     validate="True" />

이것은 기본적으로 Asp.NET 런타임에 다음과 같이 말합니다. "Hey asp.net 친구, WebResource.axd에 대한 요청이 오면 AssemblyResourceLoader를 사용하여 요청을 처리하십시오."

제발 주의를 WebResource.axd와이 파일 아닙니다 에 (내가 말할 수있는 경우) 단순히지도 AssemblyResourceLoader. 핸들러가 등록 된 이름입니다. 내 컴퓨터에서 다음 .axd 핸들러를 찾았습니다.

<add path="eurl.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="True" />
<add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="True" />
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
<add verb="*" path="*_AppService.axd" 

좋아요, 그 핸들러는 무엇을합니까?

AssemblyResourceLoader그것을 제공 (브라우저, 즉 클라이언트로 전송) 할 수 있도록 어셈블리 내에 포함 된 파일을 찾는 방법을 알고 있습니다. 예를 들어 asp.net 웹 양식에서 유효성 검사 컨트롤을 사용하는 경우 일부 자바 스크립트에 의존하여 웹 페이지에 오류를 표시합니다. 그러나 해당 javascript는 어셈블리에 포함됩니다. 브라우저에는 javascript가 필요하므로 페이지의 html에서 다음을 볼 수 있습니다.

<script src="/YourSite/WebResource.axd?d=fs7zUa...&amp;t=6342..." type="text/javascript"></script>

AssemblyResourceLoader자바 스크립트가 쿼리 문자열의 정보를 사용하여 내장 된 어셈블리를 찾아 자바 스크립트를 반환합니다.


질문으로 돌아 가기

따라서 질문에 답하기 위해 무엇입니까?

routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

이는 라우팅 엔진에 해당 경로 패턴과 일치하는 요청을 처리하지 않을 것임을 알리는 것입니다. 즉, .axd요청을 처리하지 않습니다 . 왜? MVC 자체가 유사한 HttpHandler를하기 때문에 .axd.aspxweb.config 파일에있는 다른 많은 핸들러는. MVC 처리기는 어셈블리에서 포함 된 리소스를 찾는 것과 같은 요청을 처리하는 방법을 알지 못합니다 AssemblyResourceLoader. MVC는이 질문과 답변의 범위를 벗어난 모든 작업을 수행하는 방법을 알고 있습니다.

여기.axd 에 더 자세히 설명하는 훌륭한 기사가 있습니다.


The route with the pattern {resource}.axd/{*pathInfo} is included to prevent requests for the Web resource files such as WebResource.axd or ScriptResource.axd from being passed to a controller.

Read link: http://msdn.microsoft.com/en-us/library/cc668201%28v=vs.100%29.aspx

You can also specify that routing should not handle certain URL requests. You prevent routing from handling certain requests by defining a route and specifying that the StopRoutingHandler class should be used to handle that pattern. When a request is handled by a StopRoutingHandler object, the StopRoutingHandler object blocks any additional processing of the request as a route. Instead, the request is processed as an ASP.NET page, Web service, or other ASP.NET endpoint. You can use the RouteCollection.Ignore method (or RouteCollectionExtensions.IgnoreRoute for MVC applications) to create routes that use the StopRoutingHandler class.


Take a look in the below link: http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx


Those are not files (they don't exist on disk) - they are just names under which some HTTP handlers are registered.

참고URL : https://stackoverflow.com/questions/9016650/what-is-routes-ignorerouteresource-axd-pathinfo

반응형