Reputation: 1968
I'm setting up a webapi application with an angular front-end. I want to enable html5mode, so the web server needs to have a re-write rule that sends all requests back to the index page.
The problem is the actions in the /api route are matching this rule of course, so none of my REST calls will pass through the rewrite rule.
I'm sure I'm not alone with this problem. Can anyone share the section of the web.config so that my REST service works and html5mode isn't broken?
Upvotes: 6
Views: 3155
Reputation: 1968
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<rewrite>
<rules>
<rule name="Main Rule" 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" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
Upvotes: 9