Click here to Skip to main content
16,016,140 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerDebrief: Configuration.Save Writes Invalid Configuration File Pin
Member 1266077627-Oct-21 10:18
Member 1266077627-Oct-21 10:18 
GeneralRe: Debrief: Configuration.Save Writes Invalid Configuration File Pin
Peter_in_278027-Oct-21 10:54
professionalPeter_in_278027-Oct-21 10:54 
GeneralRe: Debrief: Configuration.Save Writes Invalid Configuration File Pin
Member 1266077627-Oct-21 11:20
Member 1266077627-Oct-21 11:20 
GeneralRe: Debrief: Configuration.Save Writes Invalid Configuration File Pin
Peter_in_278027-Oct-21 11:40
professionalPeter_in_278027-Oct-21 11:40 
GeneralRe: Debrief: Configuration.Save Writes Invalid Configuration File Pin
phil.o27-Oct-21 11:46
professionalphil.o27-Oct-21 11:46 
QuestionMVC Controller State Managment Pin
Kunal Mandloi13-Sep-21 22:18
Kunal Mandloi13-Sep-21 22:18 
AnswerRe: MVC Controller State Managment Pin
Richard Deeming13-Sep-21 22:26
mveRichard Deeming13-Sep-21 22:26 
AnswerRe: MVC Controller State Managment Pin
Kunal Mandloi14-Sep-21 4:18
Kunal Mandloi14-Sep-21 4:18 
This is my home controller....
Where I am passing value in query string.......


using IdentityModel.Client;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Newtonsoft.Json;
using NLog;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Newtonsoft;
using System.Text.RegularExpressions;
using System.Net.Http.Headers;
using System.Diagnostics;
using Newtonsoft.Json.Linq;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace MYApp.Controllers
{

    public class HomeController : Controller
    {
       
       
       
        Logger logger = LogManager.GetCurrentClassLogger();
        private string clientId = "";
        private string clientSecret = "";
        
        private ModelStateDictionary ValidationMessages { get; set; }

         

        public class UserInfo

        {
            public string Addresses { get; set; }
            public string OriginatorNo { get; set; }

            public string OriginatorName { get; set; }

            public string ContactName { get; set; }

            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Email { get; set; }

        }
     
       
        public IActionResult Index()
        {
          
            try
            {

                //int a = 0;
                //int b = 1;
                //int c = b / a;
          

            string strUrl = "https://url";
          

                if (Request.Query["UserName"].ToString() != string.Empty && Request.Query["Password"] != string.Empty)
                {

                  
                    HttpContext.Session.SetString("UserName", Request.Query["UserName"].ToString());
                   
                    HttpContext.Session.SetString("Password", Request.Query["strPassword"].ToString());
                   
                }
                
              
   

            }
            catch (Exception ex)
            {
                

            }
    

        }

       
        public class ContactPerson
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Email { get; set; }
            public string IncludeInEmails { get; set; }
        }
      
        public IActionResult DataBase_Import(string Json,string page)
        {
            string DecodeJson = "";
            string strNUrl = "";
            string pageName = page;
            string strToken = "";
            string strRefreshToken = "";
            string strAuthToken = "";
          

            

            if (HttpContext.Session.GetString("UserName") != null)
            {
                if (HttpContext.Session.GetString("UserName") != "")
               {
                    UserName = HttpContext.Session.GetString("UserName");
                }
            }

            if (HttpContext.Session.GetString("Password") != null)
            {
               if (HttpContext.Session.GetString("Password") != "")
                {
                   Password = HttpContext.Session.GetString("Password");
               }
            }
             
           Data Logic here......
            

        }
      
}


This is My Webbooks Controller

I am trying to get username and password on this controller so that whenever the event is fired I can update my database based on username and password.


using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.ComponentModel;
using Newtonsoft.Json;
using XeroApp.dto;
using Newtonsoft.Json.Linq;
using System.Data;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using XeroApp.Models;

namespace XeroApp.Controllers
{

[Route("/webhooks")]
public class WebhooksController : Controller
{
public string strEventCategory = "";
public string strresourceId = "";
public string eventDateUt = "";
public string eventType = "";
public string strTenanId = "";
public string agrno = "", EmailId = "", Password = "", RedirectUrl = "";

private readonly IOptions<webhooksettings> webhookSettings;


private readonly ConcurrentQueue<payload> payloadQueue = new ConcurrentQueue<payload>();

private BackgroundWorker _ProcessPayloadWorker = new BackgroundWorker();

public WebhooksController(IOptions<webhooksettings> webhookSettings)
{
this.webhookSettings = webhookSettings;

// Configure background worker
_ProcessPayloadWorker.WorkerSupportsCancellation = true;
_ProcessPayloadWorker.DoWork += ProcessPayloadWorker_DoWork;
}

// Method called when webhook notification sent
[HttpPost]
public IActionResult Index()
{
string val = "";
string strToken = "";
string strRefreshToken = "";
string strAuthToken = "";

if (HttpContext.Session.GetString("UserName") != null)
{
if (HttpContext.Session.GetString("UserName") != "")
{
UserName = HttpContext.Session.GetString("UserName");
}
}


if (HttpContext.Session.GetString("Password") != null)
{
if (HttpContext.Session.GetString("Password") != "")
{
Password = HttpContext.Session.GetString("Password");
}
}


var payloadString = GetRequestBody().Result.ToString();
var signature = Request.Headers[webhookSettings.Value.XeroSignature].FirstOrDefault();
string strPdfSrtring = "";
if (!VerifySignature(payloadString, signature))
{
// Webhook signature invalid, reject payload
return Unauthorized();
}
else
{

// lstEvents = payloadString.ToList<xerowebhookevent>;
// List<xerowebhook> selectedCollection = payloadString.ToList<xerowebhook>;

}

JsonConvert.DeserializeObject<payload>(payloadString);
// Valid signature, enqueue payload to queue and start asynchronous processing of payload
payloadQueue.Enqueue(JsonConvert.DeserializeObject<payload>(payloadString));

foreach(var item in payloadQueue)
{
foreach(var eve in item.Events)
{
strEventCategory = eve.EventCategory.ToString();
eventDateUt = eve.EventDateUtc.ToString();
eventType = eve.EventType.ToString();
strresourceId = eve.ResourceId.ToString();
strTenanId = eve.TenantId.ToString();




if (strresourceId != ""&& UserName!="")
{
if (eve.EventCategory.ToString() == "INVOICE")
{

// HelpClass.GetInvoiceById(strresourceId);
}
if (eve.EventCategory.ToString() == "CONTACT")
{
HelpClass.GetContactById(UserName,Password);

}
HelpClass.WebHookEventInsert(UserName,Password);
}


}
_ProcessPayloadWorker.RunWorkerAsync();

return Ok();
}



// Validate webhook signature, signature must match hash of json payload using webhook key as the hash key
private bool VerifySignature(string payload, string signature)
{
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(webhookSettings.Value.WebhookKey);
byte[] payloadByte = encoding.GetBytes(payload);

using (var hmac = new HMACSHA256(keyByte))
{
byte[] hashMessage = hmac.ComputeHash(payloadByte);
var hashMsg = Convert.ToBase64String(hashMessage);
return Convert.ToBase64String(hashMessage) == signature ? true : false;
}
}

// Invokes background worker to process payload
private void ProcessPayloadWorker_DoWork(object sender, DoWorkEventArgs e)
{
ProcessPayloadQueue();
}

// Use method to process payloads
private void ProcessPayloadQueue()
{
while (payloadQueue.Count > 0)
{
payloadQueue.TryDequeue(out Payload payload);
foreach (PayloadEvent payloadEvent in payload.Events)
{
// Process payloads here
Debug.WriteLine("\nEvent Type: " + payloadEvent.EventType.ToString());
Debug.WriteLine("Event Category: " + payloadEvent.EventCategory.ToString() + "\n");
}
}
}

}


}

Kindly provide the solution through which i can get the required values whenever the webbooks event is fired

modified 14-Sep-21 10:27am.

QuestionFramework v. Core for Windows App Pin
Richard Andrew x644-Sep-21 1:47
professionalRichard Andrew x644-Sep-21 1:47 
AnswerRe: Framework v. Core for Windows App Pin
Dave Kreskowiak4-Sep-21 4:46
mveDave Kreskowiak4-Sep-21 4:46 
AnswerRe: Framework v. Core for Windows App Pin
Richard Deeming5-Sep-21 22:10
mveRichard Deeming5-Sep-21 22:10 
QuestionUsing Postman to test HTTPPatch in .Net Core API, [FromBody] JsonPatchDocument<TEntity> patchEntity is null Pin
thewizardoftn27-Aug-21 9:52
thewizardoftn27-Aug-21 9:52 
AnswerRe: Using Postman to test HTTPPatch in .Net Core API, [FromBody] JsonPatchDocument<TEntity> patchEntity is null Pin
Richard Deeming30-Aug-21 22:03
mveRichard Deeming30-Aug-21 22:03 
AnswerRe: Using Postman to test HTTPPatch in .Net Core API, [FromBody] JsonPatchDocument<TEntity> patchEntity is null Pin
Matt T Heffron31-Aug-21 11:45
professionalMatt T Heffron31-Aug-21 11:45 
QuestionVisual Studio 2019 - unable to add data connection Pin
Member 1299459619-Aug-21 1:49
Member 1299459619-Aug-21 1:49 
AnswerRe: Visual Studio 2019 - unable to add data connection Pin
Richard MacCutchan19-Aug-21 2:27
mveRichard MacCutchan19-Aug-21 2:27 
QuestionVisual studio 2019 Pin
Member 1105128618-Aug-21 19:57
Member 1105128618-Aug-21 19:57 
AnswerRe: Visual studio 2019 Pin
Richard Deeming18-Aug-21 22:03
mveRichard Deeming18-Aug-21 22:03 
QuestionTextbox control with the x in top right hand corner Pin
pkfox12-Jul-21 4:18
professionalpkfox12-Jul-21 4:18 
AnswerRe: Textbox control with the x in top right hand corner Pin
SeeSharp212-Jul-21 5:35
SeeSharp212-Jul-21 5:35 
GeneralRe: Textbox control with the x in top right hand corner Pin
pkfox12-Jul-21 10:49
professionalpkfox12-Jul-21 10:49 
GeneralRe: Textbox control with the x in top right hand corner Pin
SeeSharp213-Jul-21 1:15
SeeSharp213-Jul-21 1:15 
GeneralRe: Textbox control with the x in top right hand corner Pin
pkfox13-Jul-21 3:57
professionalpkfox13-Jul-21 3:57 
GeneralRe: Textbox control with the x in top right hand corner Pin
SeeSharp213-Jul-21 6:12
SeeSharp213-Jul-21 6:12 
GeneralRe: Textbox control with the x in top right hand corner Pin
pkfox13-Jul-21 6:30
professionalpkfox13-Jul-21 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.