2014-09-03 2 views
6

링크 용 URL 재 작성을 사용하는 AngularJS 응용 프로그램이 있습니다. 내가 SO에이 솔루션을 발견IIS URL 다시 쓰기 규칙

<rewrite> 
<rules> 
    <rule name="MainRule" stopProcessing="true"> 
    <match url=".*" /> 
    <conditions logicalGrouping="MatchAll"> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="^api/(.*)" negate="false" /> 
    </conditions> 
    <action type="Rewrite" url="Default.cshtml" /> 
    </rule> 
</rules> 

: How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode? 내 API가 통과 할 수 있도록 한 수정했다처럼 내 재 작성 규칙 보인다.

본질적으로 모든 내 요청을 Default.cshtml 내 웹 API 호출을 제외하고 리디렉션하고 싶습니다. 이 기능은 기본 URL에 localhost/myapp과 같은 앱을로드 할 때 매우 효과적입니다. 내가 같이 각 노선에 페이지를 다시로드하는 경우에는 : localhost/myapp/dashboard이 말하는 실패 :

<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost/myapp/dashboard'.</Message> 
<MessageDetail>No type was found that matches the controller named 'dashboard'.</MessageDetail></Error> 

내가했던 곳 주위에 작업이 있습니다

<rewrite> 
    <rules> 
    <rule name="Default" stopProcessing="true"> 
     <match url="^(?!lib|api|dist|assets|app/|bower|common|main|signalr|templates|bower_components/).*" /> 
     <action type="Rewrite" url="Default.cshtml" /> 
    </rule> 
    </rules> 
</rewrite> 

을하고 그것을 잘 작동했다. 위의 클리너 솔루션을 어떻게 활용하고 재 작성을 수행 할 수있는 아이디어가 있습니까?

답변

6

패턴을 변경하고 {REQUEST_FILE}{REQUEST_URI}으로 변경해야합니다. 내 데모보기 :

<rewrite> 
    <rules> 
    <rule name="MainRule" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAll"> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" /> 
     <add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="Default.cshtml" /> 
    </rule> 
    </rules> 
</rewrite> 
+0

그 signalr 패턴은 생명의 은인이었습니다. 그것으로 몇 시간 동안 고생했다. 미래의 사용자를위한 또 다른 포인트는 startup.cs app.start()에서 자신의 루트 경로를 지정하면 문제가 발생한다는 것입니다. "/ www"의 루트 경로를 제거해야만 signalR 매핑에 그대로 두어야했습니다. –

+0

나는 당신을 사랑한다. 귀하의 신호기는 생명의 은인 ²되었습니다. 그냥 Admin (내 폴더 응용 프로그램)으로 변경하고 매력처럼 일했습니다. 나는 이것이 디자이너가하는 일이라는 것을 알지 못한다. 그러나 그것은 효과적이다. 고마워. –