[英]How to resolve AJAX.POST response as 301 when I am using URL redirection in web.config?
因此,花了很多時間后,我不得不問這個問題。 我正在ASP.NET中發送AJAX POST請求
$.ajax({
type: "POST",
url: "Manage.aspx/StUpdate",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8"
});
我的Web.config刪除了所有.aspx擴展規則,如下所示:
<rewrite>
<rules>
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
我試圖將AJAX POST發送到URL:Manage / StUpdate,這沒有用。
我讀了很多書之后,才知道,唯一允許我繼續進行此AJAX POST方法的方法是不對該特定文件進行重寫。
我的理解正確嗎? 除了更改URL重寫以外,還有其他方法嗎?
如果必須從重寫中刪除此特定文件,該怎么辦?
問題已解決。 如果有人遇到類似問題,則可以使用web.config解決方案。
<rewrite>
<rules>
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/Login.aspx" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/Login.aspx" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
</rules>
</rewrite>
解決方案是確保在刪除和添加ASPX條件中都排除要避免的特定URL。 我了解該屬性negate =“ true”的統計信息可避免在應用此規則時出現這種情況。 我通過試錯法了解它。 不確定是否正確。
希望它能幫助有需要的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.