如何解决ASP.使用子目录时,NET相对url问题
本文关键字:子目录 NET 相对 问题 url 何解决 解决 ASP | 更新日期: 2023-09-27 18:01:41
我现在的ASP。. NET根是localhost:2343/Project/FleetUM
问题是,从javascript,如果我做一个AJAX请求url作为/{controller}/{action}
,请求是localhost:2343/{controller}/{action}
而不是localhost:2343/Project/FleetUM/{controller}/{action}
,谁能帮助我如何解决这个问题。我应该为此使用URL重写吗?
是的,你应该重写
这是我的工作
<rules>
<rule platformId="wdpVpr" name="www.your-website-name.com virtual path rewrite" stopProcessing="true">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www'.your-website-name'.com$" />
<add input="{PATH_INFO}" pattern="^/your-subfolder/" negate="true" />
</conditions>
<action type="Rewrite" url="/your-subfolder/{R:0}" appendQueryString="true" />
</rule>
<rule platformId="wdpVpr" name="your-website-name.com virtual path rewrite" stopProcessing="true">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^your-website-name'.com$" />
<add input="{PATH_INFO}" pattern="^/your-subfolder/" negate="true" />
</conditions>
<action type="Rewrite" url="/your-subfolder/{R:0}" appendQueryString="true" />
</rule>
</rules>
<outboundRules>
<rule name="www.your-website-name.com virtual path rewrite">
<match serverVariable="RESPONSE_LOCATION" pattern="^(?:your-subfolder|(.*//[_a-zA-Z0-9-'.]*)?/your-subfolder)(.*)" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
</conditions>
<action type="Rewrite" value="{R:1}/{R:2}" />
</rule>
<rule name="your-website-name.com virtual path rewrite">
<match serverVariable="RESPONSE_LOCATION" pattern="^(?:your-subfolder|(.*//[_a-zA-Z0-9-'.]*)?/your-subfolder)(.*)" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
</conditions>
<action type="Rewrite" value="{R:1}/{R:2}" />
</rule>
</outboundRules>
我遵循这个由两部分组成的教程。这是一个伟大的http://weblogs.asp.net/owscott/iis-url-rewrite-hosting-multiple-domains-under-one-site
你可以尝试发送一个url等于:
的请求~/{controller}/{action}
~(波浪)通常指的是主目录,在您的例子中似乎是localhost:2343/Project/FleetUM