我试图在我的项目中实现url重写。它工作正常,但所有WebMethods在url重写后都无法正常工作。我用HttpModule做了这件事。以下是我的代码。你能帮我吗?
客户端
function MyMethod() {
$.ajax({
type: 'POST',
url: 'Test.aspx/TestMethos',
async: true,
cache: true,
dataType: 'json',
contentType: 'application/json;charset=utf-8',
data: '{}',
success: function (data) {
//MyCode
},
error: function (request, status, error) {
if (request.statusText == 'Unauthorized') {
//Logout
}
}
的WebMethod
[WebMethod]
public static string TestMethod()
{
return "Hi Test";
}
HttpModule重写C#代码
HttpApplication MyApp = (HttpApplication)sender;
string MyOldPath = MyApp.Request.Path;
string OriginalURL = string.Empty;
switch (MyOldPath.ToLower())
{
case "/home":
string selectedQueryString = MyApp.Request.QueryString.ToString();
OriginalURL = "~/Modules/UserMgmt/Home.aspx";
break;
case "/star performer":
OriginalURL = "~/Modules/UserMgmt/BestEmployee.aspx";
break;
case "/test.aspx/testmethos;:
OriginalURL = "~/Modules/UserMgmt" + MyOldPath;
break;
}
if (OriginalURL != string.Empty)
MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty);