Issue Reproduction Steps:
- To replicate the issue, follow these steps:
- Open Visual Studio 2013 and create a new project by selecting "Azure Cloud Service" under File > New. Add an "ASP.NET Web Role" to the project named WebRole1.
- Choose the "Web Forms" template for the web role.
- Incorporate jquery-1.11.1.min.js by adding it to the WebRole1 Project along with a new WebForm1.aspx file.
Add the code snippet below inside the head section of WebForm1.aspx
<script src="jquery-1.11.1.min.js"></script> <script> $(function() { $.ajax({ type: "POST", url: "WebForm1.aspx/Foo", beforeSend: function (xhr) { xhr.setRequestHeader("Content-type", "application/json; charset=utf-8"); }, contentType: "application/json; charset=utf-8", dataType: "json", data: "{a: 'webmethod!'}", success: function(data) { alert(data.d); }, error: function() { alert("error"); } }); });
Add this function to the WebForm1 class in WebForm1.aspx.cs
[WebMethod()] public static string Foo(string a) { return a; }
Set the WebRole1 project as the Startup Project and run it. The browser will display "undefined".
Furthermore, you may notice that when using a standard ASP.NET Web Form project, you can obtain the expected output "webmethod!" unlike with Azure Cloud Services. What could be causing this discrepancy?
An interesting observation was made regarding the url: "WebForm1.aspx/Foo"
: modifying the .aspx segment leads to ajax failure while changing the Foo part to any value still results in a successful ajax call. This behavior is peculiar since in regular ASP.NET Web Form applications, altering either part would trigger an error!
If you create an Empty ASP.NET Web Role instead, the ajax request will go through seamlessly!!! Why does this inconsistency occur?