以下是我从客户端代码调用Web服务的代码
$.ajax(
{
type: "POST",
url: "counter.asmx/IncreaseCounter",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: LogoutSuccess,
error: AjaxFailed
}
);
在我的本地计算机上,这是正常工作但是在生产部署之后 在服务调用时出现浏览器弹出认证框,这不允许我继续。 当我从网站的网页上调用webservice时,我想摆脱这个身份验证弹出窗口。
表示我不希望对此Web服务进行任何身份验证。
在谷歌之后,我在我的web.config文件中添加了以下节点,但它还是要求我提供凭据
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="false" />
</webServices>
</scripting>
</system.web.extensions>
请建议我这里的解决方案是我的网络服务代码
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class counter : System.Web.Services.WebService
{
public counter()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod(Description = "Per session Hit Counter", EnableSession = true)]
public void IncreaseCounter(string PostURL)
{
string url= HttpUtility.UrlDecode(PostURL);
DBAdministrator.IncreasePostVisitCount(url);
}
}
答案 0 :(得分:0)
这太奇怪了;页面和服务都应该需要身份验证,或者两者都不需要。
由于您使用相对URL,因此加载页面时应该已经弹出了auth框。之后,用户应该有一个会话。
检查两件事:
WsiProfiles.BasicProfile1_1
让我想知道......常数是什么意思? “基本”听起来像“基本认证方案”。检查是否有其他可以使用的值。