使用身份验证模式=“windows”时,为什么我的API会抛出错误 [英] Why is my API throws an error when using authentication mode=“windows”

查看:72
本文介绍了使用身份验证模式=“windows”时,为什么我的API会抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Windows模式时,我得到一个异常错误引用未声明的实体'。第69行,第41位。很奇怪。然后当我检查结果。内容执行后我得到一个html页面错误如401 - 未经授权:由于凭据无效而拒绝访问。这也是IIS服务器上发生的问题。



我尝试过:



以下是来自ActionResult的RestSharp代码



Somehow when using Windows mode, I get an Exception Error"Reference to undeclared entity 'nbsp'. Line 69, position 41."" weird. Then when I check the result.Content after executing I get like an html page with errors like 401 - Unauthorized: Access is denied due to invalid credentials. This is an issue that happens on the IIS Server too.

What I have tried:

Below is my RestSharp Code from ActionResult

var client = new RestClient(Request.Url.GetLeftPart(UriPartial.Authority).ToString());
             var request = new RestRequest("http://domain.co.za/api/student/getBookedSlotHistory", Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddObject(new StudentInput()
                {
                    StudentNumber = "219193029"//UserIdentity.Username()
                });

                var result = client.Execute<StudentBookingHistoryOutput>(request);
                var data = JsonConvert.DeserializeObject<StudentBookingHistoryOutput>(result.Content);





然后下面是我的APIController



Then below is my APIController

[HttpPost]
        [Route("api/student/getBookedSlotHistory")]
        public async Task<StudentBookingHistoryOutput> GetHistory(StudentInput input)
        {

            return await _studentRepository.GetBookingHistoryData(input);
        }

推荐答案

此行解决了问题。

This line solved the problem.
request.UseDefaultCredentials = true;

谢谢你们


这篇关于使用身份验证模式=“windows”时,为什么我的API会抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆