2012-02-01 192 views
4

有一個ASMX:ASMX asp.net web服務返回401錯誤未經授權

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

有一個HTTPS://.../a.aspx,在這個頁面,我稱之爲webserivce通過jQuery AJAX:

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

注意a.aspx使用HTTPS。 ajax請求會得到401未經授權的響應。 如果a.aspx不使用HTTPS,則它可以工作。

我正在使用名爲「WebPageSecurity」的庫,如果我使用它,401錯誤將會發生。如果我不使用它,那就是直接在瀏覽器中輸入https://.../a.aspx,那麼它就會起作用。 所以我想在WebPageSecurity中的問題,我該如何解決它?謝謝。

回答

2

最終,我找到了解決辦法:忽略的web.config中WebPageSecurity配置中的* .asmx文件:

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

我知道這不是最近的,但確實這會引起其他安全問題? – Alex 2013-09-04 09:15:17

相關問題