Asp.net 更改ASP WebApi的根路径
我的angular项目位于Asp.net 更改ASP WebApi的根路径,asp.net,.net,asp.net-web-api,Asp.net,.net,Asp.net Web Api,我的angular项目位于app文件夹中,因此我引用该项目时必须将其发送至http://localhost:45485/app,但我想从此url中删除应用程序。我正试着这样做,但没用。我不知道该怎么办,请帮帮我 web.config文件: <rewrite> <rules> <clear/> <rule name="app" stopProcessing="true"> <match url="^(.+)$"
app
文件夹中,因此我引用该项目时必须将其发送至http://localhost:45485/app
,但我想从此url中删除应用程序。我正试着这样做,但没用。我不知道该怎么办,请帮帮我
web.config文件:
<rewrite>
<rules>
<clear/>
<rule name="app" stopProcessing="true">
<match url="^(.+)$" />
<conditions>
<add input="{APPL_PHYSICAL_PATH}app\{R:1}" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
<rule name="index.html as document root" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="/app/index.html" />
</rule>
</rules>
</rewrite>
我可能不明白这个问题的“目的”或要点,所以假设你只是想让你的SPA成为“主要”切入点(又名http://example.com/
),当您的Angular assets都在/app
文件夹中时,就不需要修改重写规则,也不需要影响(整个)Asp.Net/MVC/Web Api
应用程序(由于重写规则)
不是一个有棱角的“专家”,所以这是一个需要改进的小例子:
- 您的
ng应用程序
可以完全位于ASP.Net MVC/Web Api的“默认”(“主页”->“索引”)视图
应用程序的“容器”(如果愿意的话)。无需/无需“重写”规则即可将其作为网站的“索引”(第一页/默认页)
index.cshtml
MVCView
使用
- 使用ui路由器(见上面的链接),它会像这样运行
$stateProvider
.state('home', {
templateUrl: '/app/index.html' //maps to root -> app -> index.html
})
.state('foo', {
templateUrl: '/app/page2.html' //maps to root -> app -> page2.html
})
请注意,我使用的是templateUrl
中指向资源的完整路径(“根相对路径”),因为它映射到您的网站/应用程序文件夹,而不仅仅是相对路径(指向app
子文件夹)
Hth.虽然我对如何(正确地)做到这一点很感兴趣,但对“为什么”很好奇?对于“web api”应用程序?如果这是一个前端角度项目(仅限),那么它似乎是“方孔中的圆桩”…@EdSF,我只是研究了所有内容,不理解某些时刻,但为什么不呢?在我看来,这是真的,所以我想试试。
/app
index.html
page2.html
$stateProvider
.state('home', {
templateUrl: '/app/index.html' //maps to root -> app -> index.html
})
.state('foo', {
templateUrl: '/app/page2.html' //maps to root -> app -> page2.html
})