Calling asp.net asmx webservice via ajax returns 401 Unauthorized error

There is asmx:

[WebService] [ScriptService] public class MyService : WebService { [WebMethod] public OperationResult Validate(string str) { } } 

There https : //.../a.aspx, on this page I call webserivce via jQuery ajax:

 $.ajax({ url: '/Services/MyService.asmx/Validate', type: 'POST', contentType: 'application/json; charset=utf-8', data: data, success: function (data, textStatus, xhr) { // xxx } }); 

Note that a.aspx uses HTTPS . Ajax request will receive 401 Unauthorized response. If a.aspx does not use HTTPS, it works.

I use a library called "WebPageSecurity", if I use it, error 401 will occur. If I do not use it, then there is a direct occurrence of https: //.../a.aspx in the browser, then it will work. So I think the problem is in WebPageSecurity, how can I fix it? Thanks.

+4
source share
1 answer

In the end, I found a solution: Ignore the * .asmx file in the WebPageSecurity configuration in web.config:

  <secureWebPages mode="On" ignoreHandlers="WithStandardExtensions" encryptedUri="xxx"> <files> <add path="path/to/MyService.asmx/MyMethod" secure="Ignore" /> </files> </secureWebPages> 
+2
source

Source: https://habr.com/ru/post/1394107/


All Articles