当使用json从MVC发布时,服务器在基于令牌的web api中响应状态为500 [英] The server responded with a status of 500 in token based web api when posting from MVC using json
本文介绍了当使用json从MVC发布时,服务器在基于令牌的web api中响应状态为500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
here is my code
<script>
$('#btnLogin').click(function () {
var body = {'grant_type': 'password','Email':$('#Email').val(),'password': $('#Password').val()};
alert(JSON.stringify(body));
$.ajax({
url: 'http://localhost:46382/Token',
method: 'POST',
ContentType: 'application/x-www-form-urlencoded',
data: body,
success: function (d) {
console.log(d);
alert("Login successfully Successfully");
sessionStorage.setItem("accessToken", response.access_token);
window.location.href = 'home';
},
error: function (error) {
alert("Error ");
}
});
});
</script>
和休息web api中的所有配置都是默认的
我尝试了什么:
我也尝试将内容类型更改为application / json
我添加了
and rest all the configuration in web api is default
What I have tried:
I have also tried changing the content type to application/json
and I have added
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
网页配置中的
从代码发布时它正在工作,
但是我想要通过json
in web config
And it is working when posting from code behind,
but I want do this by json
推荐答案
('#btnLogin')执行此操作。单击(function(){
var body = {'grant_type' :'password','Email':
('#btnLogin').click(function () { var body = {'grant_type': 'password','Email':
('#Email')。val(),'password':
('#Email').val(),'password':
('#Password ')。val()};
alert(JSON.stringify(body));
('#Password').val()}; alert(JSON.stringify(body));
这篇关于当使用json从MVC发布时,服务器在基于令牌的web api中响应状态为500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文