在调试时我验证了这个 js 函数被调用了:
var oAuthManager = {
loginWithGoogle_OnClick: function () {
createAjaxRequest("Register/GetAuthorizeRequestToken", {
'providerType': 'google'}).done(function (res) { });
// createAjaxRequest("Register", null).done(function (res) { });
}
};
它调用:
function createAjaxRequest(url,data) {
return $.ajax(
{
type: "POST",
url: url,
data: data
});
};
那么为什么我不能访问这个 RegisterController 的方法?
[HttpPost] \\tried with and without this
public void GetAuthorizeRequestToken(string providerType)
{
var authType = (OAuthProviderTypes)Enum.Parse(typeof(OAuthProviderTypes), providerType);
mAuthorizationService.GetAuthorizeRequestToken(authType);
}
其他 Controller 与其他 js 一起工作正常。
我得到错误:
POST http://localhost:8976/Register/GetAuthorizeRequestToken 500 (Internal Server Error)
我有两个断点:
停止OK的ctor中的一个
webMethod 开头的第二个。我看到线程永远不会到达那里。
请您参考如下方法:
埃拉德,
我几乎可以逐行重现您的代码并且可以正常工作。那么我们来分析一下这个问题。
您没有收到 404(未找到)或 403(请求被拒绝)...您收到 500 错误,这意味着应用程序在某处损坏。
所以我会开始调查其中的一些要点:
- 您的 Controller 是否继承自基类?是否有初始化步骤失败?
- 在您的服务调用中放置一个断点。也许 VS 表现不佳,没有按应有的方式停止 Action。
如果您什么也没发现,我还会尝试以下方法来隔离问题:
- 使用 Fiddler 启动操作
- 使 js 调用更简单,以查看您是否可以执行操作(例如,没有数据的帖子)
- 在您的 ajax 调用中包含一个数据类型(虽然没有它对我有用)
这应该是一个好的开始,希望对您有所帮助,
-科沃
