我当前的ASP.NET根目录是localhost:2343/Project/FleetUM
问题是,从javascript开始,如果我使用网址/{controller}/{action}
发出AJAX请求,请求发送到localhost:2343/{controller}/{action}
而不是localhost:2343/Project/FleetUM/{controller}/{action}
,有人可以帮我解决问题这个问题。我应该使用URL重写吗?
答案 0 :(得分:0)
是的,你应该重写
这对我有用
<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
答案 1 :(得分:0)
您可以尝试使用等于:
的网址发送请求~/{controller}/{action}
〜(代字号)通常指的是你的案例中似乎是localhost:2343/Project/FleetUM
的主目录