Click here to Skip to main content
15,560,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

WebMethod is not calling when I rewrite the urls using HttpModule. Could you please help me. These are my Codes

Client Side

JavaScript
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
             }

}
JavaScript
    });
}


WebMethod

C#
[WebMethod]
public static string TestMethod()
{
    return "Hi Keedam";
}



HttpModule ReWrite C# Code

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;


}
C#
if (OriginalURL != string.Empty)
    MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty);
Posted
Updated 27-May-15 22:09pm
v3
Comments
Andy Lanng 27-May-15 8:55am    
your method TestMethod is referred to as testmethos. I would normally chalk it up to a typo but it's in there twice!

Could this be the issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900