我正在尝试将Azure应用和api托管在Azure的同一Web应用中。 但是我在访问我的api时遇到了一些困难。
文件夹结构如下:
├───api
│ └───bin
│ └───web.config <== API web.config
├───index.html
├───web.config <== Angular web.config
├───...
└───assets
├───flags
├───i18n
├───icons
└───images
因此,我需要告诉Angular web.config
将所有/api
调用重定向到api。同时仍将所有其他呼叫恢复到根文件夹中的index.html
但是我似乎无法正确解决,这是我当前的web.config。但这会将我的api调用重定向到客户端的index.html。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".woff" mimeType="font/woff" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
<mimeMap fileExtension=".ttf" mimeType="font/ttf" />
<mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<rewrite>
<rules>
<rule name="Angular Routes" 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}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="." />
</rule>
</rules>
</rewrite>
<!-- gzip compression -->
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="font/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="font/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
<location path="index.html">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
这将导致以下清单
有人知道工作web.config
吗?
UPDATE :通过将manifest.webmanifest问题添加到staticcontent中来解决此问题
答案 0 :(得分:1)
我在Azure App Services中运行了相同的设置,还遇到了试图使所有功能正常工作的问题。最后,我的SPA Apps web.config遇到的问题被API Apps继承。尝试调用我的API应用时,这导致405错误。
对我来说,解决方法是调整我的web.config并关闭继承。
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>