you don't specify which application gets the error.
your sample code just does a GET, though there is no reason to set the content-type for a GET. what happens if you just type the GET url into the browser?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We have an ASP.NET Core 3.1 Web API controller that is called from an ASP.NET web app using .NET 3.5 framework. The API controller is called via a HttpWebRequest and results in an error
That assembly does not allow partially trusted callers
Both apps reside on the same shared hosting environment and domain. That is, both app's have the same domain but are in different folders (i.e. applications) in IIS. For instance, mywebsite.com/folder1 and mywebsite.com/folder2.
Here's a sample how asp.net web app calls the .net core web api:
oRequest = HttpWebRequest.Create("https://www.mywebsite.com/folder2/path/to/api")
With oRequest
.Method = "GET"
.ContentType = "application/x-www-form-urlencoded"
.Accept = "application/json"
.ContentLength = 0
oResponse = oRequest.GetResponse()
oReader = New StreamReader(oResponse.GetResponseStream)
'store results in string
sResult = oReader.ReadToEnd
End With
We checked the .NET trust level and both app's are set to "Full (Internal)". Also, we tried adding the AllowPartiallyTrustedCallers attribute to the controller but per MS, "Partially trusted code is no longer supported. This attribute has no effect in .NET Core."
Is there another way to call the api?
Help is appreciated.
you don't specify which application gets the error.
your sample code just does a GET, though there is no reason to set the content-type for a GET. what happens if you just type the GET url into the browser?
then the error is unrelated to the code you have shown us. in some other code you are calling an untrusted assembly.
note: while you may have configured trust in the application, the IIS machine config has to be configured to allow it.
methods can not be marked AllowPartiallyTrustedCallers, only assemblies. you update the assembly.cs file with the attribute and strongly name the assembly.
typically you would do this to the library causing the trust error or wrap the library with a trusted wrapper.
@wrappingduke It is difficult to reproduce your problem, I suggest you open a case via: https://support.microsoft.com.