身份验证失败,因为远程方在调用rest api到Azure api应用程序服务时关闭了传输流 [英] Authentication failed because the remote party has closed the transport stream while calling rest api to Azure api app service

查看:135
本文介绍了身份验证失败,因为远程方在调用rest api到Azure api应用程序服务时关闭了传输流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对Azure应用服务使用rest api在.Net 4.0内置的客户端应用程序中进行身份验证.

I am trying to authenticate in client application built in .Net 4.0 using rest api against the Azure app service.

如果我们已经将应用程序部署到了Azure虚拟机,则相同的应用程序可以正常工作,但是如果将应用程序部署为

Same application works fine if we have application deployed to the azure vm but does not work if application is adeployed as 

azure应用服务.调用api的代码如下:

azure app service.Code for calling api is as follows:

字符串requestURL = ServiceBaseUrl + serviceURI;
HttpWebRequest webRequest =(HttpWebRequest)WebRequest.Create(requestURL);
webRequest.Method = Convert.ToString(method);
webRequest.Headers [HttpRequestHeader.Authorization] ="accesstoken =" + SecurityToken;

if(方法== HttpMethod.POST ||方法== HttpMethod.PUT)
{
开关(contentType)
{
case ContentType.JSON:
webRequest.ContentType =" application/json" ;;
break;
case ContentType.BINARY:
webRequest.ContentType ="application/octet-stream";
break;
case ContentType.FORM:
webRequest.ContentType ="application/x-www-form-urlencoded";
break;
默认值:
break;
}
}
IAsyncResult asyncResult = webRequest.BeginGetRequestStream(new AsyncCallback(requestStreamCallback),requestContext)

string requestURL = ServiceBaseUrl + serviceURI;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestURL);
webRequest.Method = Convert.ToString(method);
webRequest.Headers[HttpRequestHeader.Authorization] = "accesstoken=" + SecurityToken;

if (method == HttpMethod.POST || method == HttpMethod.PUT)
{
switch (contentType)
{
case ContentType.JSON:
webRequest.ContentType = "application/json";
break;
case ContentType.BINARY:
webRequest.ContentType = "application/octet-stream";
break;
case ContentType.FORM:
webRequest.ContentType = "application/x-www-form-urlencoded";
break;
default:
break;
}
}
IAsyncResult asyncResult = webRequest.BeginGetRequestStream(new AsyncCallback(requestStreamCallback), requestContext)

有人可以帮助我吗?

谢谢

Vinod

推荐答案

/& 如何捕获F12跟踪?以获取有关此问题的更多详细信息.
设置 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

You may capture a Fiddler trace /& How do I capture an F12 trace? to fetch more details on this issue. 
Set up ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 in startup code and see if that helps.

< system.web>< httpRuntime targetFramework> web.config  验证您使用的是预期的 .NET Framework版本.对于Windows窗体,请参见

For ASP.NET applications, inspect the <system.web><httpRuntime targetFramework> element of web.config to verify you're using the intended version of the .NET Framework. and for Windows Forms see How to: Target a Version of the .NET Framework.

.NET Framework的传输层安全(TLS)最佳做法,以获取有关此主题的更多详细信息.

Refer the document Transport Layer Security (TLS) best practices with the .NET Framework for more details on this topic.


这篇关于身份验证失败,因为远程方在调用rest api到Azure api应用程序服务时关闭了传输流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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