I'm writing as ASP.net web application and am using the UrlRewriting.Net module to rewrite URLs from a .html extension to the .aspx extension. One thing I've struggled with is getting Page Methods (static methods decorated with the WebMethod attribute) to work with the friendly URLs. Below is my example (page-method-test.html).
<html><head><title>Page Method Test</title><script type="text/javascript" src="<%= Request.Url.Scheme %>://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script></head><body><h1>Page Method Test</h1><div id="time">Click for Server Time</div><script type="text/javascript"> // <![CDATA[ $(document).ready(function() { // Add the page method call as an onclick handler for the div. $("#time").click(function() { alert("Getting Time"); $.ajax({ type: "POST", url: page-method-test.html/GetServerTime", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { // Replace the div's content with the page method's return. alert("Time received"); $("#time").text(msg.d); }, error: function(msg) { alert("Error"); } }); }); }); // ]]></script></body></html><script runat="server"> [WebMethod()] public static DateTime GetServerTime() { return DateTime.Now; }</script>
If I substitute page-method-test.aspx for page-method-test.html in the jQuery AJAX call it works as it should.
I get a 405 error when I leave the AJAX call with a .html extension. I can work around this problem by doing it another way (such as simply creating a services.asmx or referencing it as page-method-test.aspx), but I am curious as to why I'm getting the 405 error. Any thoughts?