WebMethod不起作用 [英] WebMethod is not workiing
本文介绍了WebMethod不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用HttpModule重写网址时,WebMethod没有调用。请你帮助我好吗。这些是我的代码
客户端
function MyMethod(){
$ .ajax({
type:' POST',
url:' Test.aspx / TestMethos',
async: true ,
cache: true ,
dataType:' json',
contentType:' application / json; charset = utf-8',
data:' {}',
成功: function (data){
// MyCode
},
错误: function (请求,状态,错误){
if (request.statusText == ' Unauthorized'){
// 退出
}
}
});
}
WebMethod
[WebMethod]
public static string TestMethod()
{
return Hi Keedam;
}
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 / testmethod :
OriginalURL = 〜/ Modules / UserMgmt + MyOldPath;
break ;
}
if (OriginalURL!= string .Empty)
MyApp.Context.RewritePath(OriginalURL, string .Empty, string .Empty);
解决方案
.ajax({
type:' POST',
url:' Test.aspx / TestMethos',
async: true ,
cache: true ,
dataType:' json',
contentType:' application / json; charset = utf-8',
d ata:' {}',
成功: function (data){
// MyCode
} ,
错误: function (请求,状态,错误){
if ( request.statusText == ' 未经授权的'){
// 退出
}
}
});
}
WebMethod
[WebMethod]
public static string TestMethod()
{
return Hi Keedam;
}
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 / testmethod :
OriginalURL = 〜/ Modules / UserMgmt + MyOldPath;
break ;
}
if (OriginalURL!= string .Empty)
MyApp.Context.RewritePath(OriginalURL, string .Empty, string .Empty);
Hi,
WebMethod is not calling when I rewrite the urls using HttpModule. Could you please help me. These are my Codes
Client Side
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 Keedam";
}
HttpModule ReWrite C# Code
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/testmethod":
OriginalURL = "~/Modules/UserMgmt" + MyOldPath;
break;
}
if (OriginalURL != string.Empty)
MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty);
解决方案
.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 Keedam"; }
HttpModule ReWrite C# Code
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/testmethod": OriginalURL = "~/Modules/UserMgmt" + MyOldPath; break;
}
if (OriginalURL != string.Empty) MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty);
这篇关于WebMethod不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文