I created C # WebMethod
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static HttpResponseMessage GetPageHtml(string file, int page)
{}
I can call it, and it works fine using Ajax, angular, Postman when I add the Content-Type: 'application / Json' header. Here is an example HTTP request that works fine.
$http({
url: 'default.aspx/GetPageHtml?file=' + JSON.stringify(selectedFile) + '&page=' + itemNumber,
method: "GET",
headers: { 'Content-Type': 'application/json' },
data:''
}).then(function successCallback(response) {
return response.d;
}, function errorCallback(response) {
});
But when I call the same method as for iframe ng-src, it does not work.
<iframe ng-src="default.aspx/GetPageHtml?file=candy.pdf&page=1" style="height: 150px;"></iframe>
I tested this Http call with the Google Chrome Developers tools and found that the Content-Type is "text / html", so it doesn't hit my WebMethod. See This Screenshot.
Iframe ng-src
I knew a lot about Google and Stackoverflow, but I could not find the reason I needed to provide Content-Type: "application / json" to call my WebMethod