我在我的aspx页面中使用ajax调用,并使用URL Rewrite。 Ajax调用在没有URL重写规则的情况下点击webMethod但在应用重写规则后它停止工作。
我的aspx页面ajax调用是:
$.ajax({
type: "POST",
url: "../cc/page.aspx/SendNewsletter",
data: d,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert('hi');
if (response.d == "1") {
alert("Newsletter has been sent successfully.");
}
else {
alert("Something went wrong.Please try again later.");
}
},
failure: function (response) {
alert(response.d);
}
}).always(function () {
});
我的Web方法是:
[WebMethod]
public static string SendNewsletter(string to, string newsletter, string newslettername)
{
}
我的重写规则是:
<rule name="Rewrite normal CC request to aspx">
<match url="^cc/(.*)$" />
<action type="Rewrite" url="cc/{R:1}.aspx" />
</rule>
答案 0 :(得分:0)
您的urlrewriterule正在将您的原始网址/cc/page.aspx/SendNewsletter
转换为/cc/page.aspx/SendNewsletter.aspx
将规则更改为以下
<rule name="Rewrite normal CC request to aspx" stopProcessing="true">
<match url="^cc/([^/]*)/(.*)$" />
<action type="Rewrite" url="cc/{R:1}.aspx/{R:2}" />
</rule>
<rule name="Rewrite normal CC" stopProcessing="true">
<match url="^cc/([^?]*)?(.*)$" />
<action type="Rewrite" url="cc/{R:1}.aspx?{R:2}" />
</rule>
并将您的网址更改为../cc/page/SendNewsletter