UPDATE: The core issue is ABPSesssion gets null after the postasync request. i think if i can regain back my abpsssion it will work.
I am trying to make an api call of postAsync type. Issue is i am getting the response perfectly well now when i i try to save that response in my database using createAsync i get an exception for object instance . I checked the logs all it says is " Policy execution failed. Request origin http://localhost:21021 does not have permission to access the resource. "
The same thing is working perfectly fine for getasync api calls. What should I do, I did logged in from admin account that has all rights
//code
HttpClient client = new HttpClient();
var SLACK_TOKEN = OneConsts.SlackToken;
var values = new Dictionary<string, string>
{
{ "token", SLACK_TOKEN },
{ "name", "contacts2" },
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://slack.com/api/conversations.create", content);
var data = response.Content.ReadAsStringAsync().Result;
JObject obj = JObject.Parse(data);
foreach (var item in obj["channel"])
{
input.ChannelId = obj["channel"]["id"].ToString();
input.ChannelName = obj["channel"]["name"].ToString();
input.JSONinfo = obj["channel"].ToString();
var slack = SlackConnector.Create(input.ChannelId, input.ChannelName, input.JSONinfo);
await _slackconnectorManager.CreateAsync(slack);
CurrentUnitOfWork.SaveChanges();
MapToEntityDto(slack);
The exception:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.AspNetCore.Http.Extensions
StackTrace:
at Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(HttpRequest request)
at Abp.EntityHistory.EntityHistoryHelper.CreateEntityChangeSet(ICollection1 entityEntries) at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext3.d__98.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.d__20.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.d__12.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.d__14.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Domain.Uow.UnitOfWorkBase.d__57.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Domain.Uow.UnitOfWorkInterceptor.<>c__DisplayClass6_0.<b__2>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Threading.InternalAsyncHelper.d__51.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Davigold.One.Crm.SlackConnector.SlackConnectorManager.d__4.MoveNext() in C:\Users\dell\source\repos\Davigold\OneDavigold\src\Davigold.One.Core\Crm\SlackConnector\SlackConnectorManager.cs:line 58
This exception was originally thrown at this call stack:
[External Code]
Davigold.One.Crm.SlackConnector.SlackConnectorManager.CreateAsync(Davigold.One.Crm.SlackConnector.SlackConnector) in SlackConnectorManager.cs
The issue was simple await with postasync i replaced that line with var response = client.PostAsync("https://slack.com/api/conversations.create", content).Result;
User contributions licensed under CC BY-SA 3.0