2014-09-16 3 views
0

:HttpContext.RewritePath() 금지 HTTP 모듈 생산량 (403)에서 나는 다른 폴더의 파일에 대한 요청을 다시 다음 HTTP 모듈을 사용하고 싶습니다

public class MyHttpModule : IHttpModule 
{ 
    public void Init(HttpApplication application) 
    { 
     application.BeginRequest += (sender, e) => 
      { 
       var httpApplication = (HttpApplication)sender; 
       var httpContext = httpApplication.Context; 

       if (httpContext.Request.Url.ToString().Contains("styles/style.css")) 
       { 
        httpContext.RewritePath("~/some/other/folder/styles/style.css"); 
       } 
      }; 
    } 

    public void Dispose() { } 
} 
코드는 예상대로 작동하는 것 같다

(예 후를 RewritePath()Request.Url에는 다시 작성된 URL이 들어 있지만 스타일/style.css를 열려고하면 403.2 금기 오류가 발생합니다.

RewritePath() 호출 후 Request.Url에서 가져온 URL을 열면 CSS 파일이 올바르게 표시됩니다 (예 : styles/style.css와 같은 내용을 열고 일부/기타/폴더/스타일 /style.css).

실패한 요청 추적은 또한 내 모듈이 올바른 다시 쓰기를 수행함을 보여줍니다. 오류에 해당하는이 추적 항목 :

82. -NOTIFY_MODULE_END 
ModuleName ManagedPipelineHandler 
Notification MAP_REQUEST_HANDLER 
fIsPostNotificationEvent false 
NotificationStatus NOTIFICATION_CONTINUE 

83. -MODULE_SET_RESPONSE_ERROR_STATUS 
ModuleName IIS Web Core 
Notification MAP_REQUEST_HANDLER 
HttpStatus 403 
HttpReason Forbidden 
HttpSubStatus 2 
ErrorCode Access is denied. (0x80070005) 

84. -SECURITY_DENIED_BY_ACCESS_FLAGS 
CurrentFlags 512 
NeededFlags 1 

는 지금까지 내가 그것을 말할 수있는 AccessRead (1) 권한이 필요하지만, (512) AccessScript을 (this topic 참조)를 얻었다. 후자가 이전보다 더 높은 권한 수준이라고 생각하기 때문에 이것은 나에게 퍼즐입니다.

해당 파일의 폴더에 대한 파일 시스템 사용 권한을 변경해도 영향을 미치지 않습니다 (Everyone에게 모든 권한을 부여해도 도움이되지 않음). 앱 풀은 내 사용자 (관리자 계정)를 ID로 사용합니다 (그러나 AppPoolIdentity에 남겨두면이 중 하나가 도움이되지 않습니다).

<handlers accessPolicy="Script,Read"> 
    <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" /> 
</handlers> 

는 IIS URL 재 작성 모듈 작품과 같은 재 작성을 수행 :

파일의 폴더는 중요한 경우이 들어있는의 Web.config있다.

업데이트 :주의

그 (바로 위의 핸들러 선언과의 Web.config를 포함하는 (즉, ~/스타일 /있는 style.css) 원래 존재하지 않는 경로에 물리적 폴더를 생성 플러스 system.webServer 등을 사용하는 일반적인 의식)로 인해 오류가 사라집니다. 당연히 이것은 나를위한 해결책이 아니지만 최소한 힌트를줍니다.

갱신 2는 :

나는 빈 ASP.NET 응용 프로그램 몇 가지 테스트를했다. 루트 Web.config에서 모듈 만 설정하고 Web.config를 Styles 폴더에 추가하지 않는 것이 효과적입니다.

루트 Web.config에이 내용을 추가하면 (원래 응용 프로그램의 Web.config에서 가져온 것임) 오류가 발생했습니다. 하아!

<handlers accessPolicy="Script"> 
    <clear /> 
</handlers> 

"Script, Read"에 대한 accessPolicy 수정. 문제가 해결되었습니다 ...

누군가가 설명해 주시겠습니까?

+0

오차드를 사용하지 않는 재현을 제공 할 수 있습니까? 다른 사람들과 솔루션을 공유 할 수 있습니까? –

+0

감사합니다. – Piedone

답변

0

"some"폴더 [~/some/other/folder/styles/style.css]에 web.config를 만들고 하위 폴더의 모든 web.config 파일을 삭제하려고 할 수 있습니다. 유일한 web.config에서 다음을 시도해 볼 수 있습니다 :

<handlers accessPolicy="Script,Read"> 
    <!-- 
    iis7 - for any request to a file exists on disk, return it via native http module. 
    accessPolicy 'Script' is to allow for a managed 404 page. 
    --> 

    <add name="StaticFileHandler" path="*" verb="*" modules="StaticFileModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" /> 
</handlers> 
+0

고마워요.하지만 이것도 마찬가지입니다. "some"폴더에는 이제이 경로의 하위 폴더 만 포함되고 Web.config와 함께 하나의 styles.css (원래 파일을 시도한 후 자신의 파일을 보았습니다)가 방해를받지 않게되었습니다. – Piedone