|
Thanks for the feedback. How do I do this? Or is that a forum SysAdmin prerogative?
|
|
|
|
|
Start here[^]
If you run into any problems, post a message in that forum and Sean Ewington will pop up to help you.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Member 12660776 wrote: How do I do this?
You could start here: Submit a new Article[^]
And no, you do not need admin prerogatives to submit an article/tip/trick/reference.
Yours would make a nice tip/trick, indeed. The process of finding the cause is at least as important as the actual resolution, imho.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
I am working on Webhooks Concept. Since Webhooks act like an trigger. It will be firing an event like Update or Insert takes place. Its a MVC application and I have two Controller Home and Webhook Controller. I am passing argument through Query String on Home controller. I have tried Session,TempData, Cookies for passing variable from home to Webhooks HttpContext.Session.SetString("UserName", Request.Query["UserName"].ToString());
and getting session value on webhook controller
HttpContext.Session.GetString("UserName");
Also tried the same for TempData
Issue is On webbooks Controller its coming null.
I need to store parameter (User Name ,password) and reused the same for database related operation
Kindly guide
|
|
|
|
|
Session and TempData both rely on cookies to identify the requesting browser. They have a limited life-span, so data you store in them won't hang around forever.
If the data isn't available in the web-hook request, that means either the session has timed out between the initial request and the hook request; or the hook request was made from a different process than the initial request, or using a tool which doesn't store the cookies you set.
You will need to find a different solution. Since you haven't provided any details of what you're actually trying to do, we can't offer any suggestions.
NB: Storing credentials in memory is not a good idea.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
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
{
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.
|
|
|
|
|
I'm now designing a new application that will run only on Windows. No other platforms.
Is there any reason to develop it in .NET Core as opposed to Framework?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
AFAIK, .NET Framework 4.8 is the last of the Windows specific framework. Everything goes .NET (Core) from now on, so it's only a matter of time before your app needs to be converted to a .NET app.
|
|
|
|
|
Technically, the choice is between .NET Framework 4.8 and .NET 5 now.
Announcing .NET 5.0 | .NET Blog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
[HttpPatch("{id:int}")]
public async Task<IActionResult>UpdatePartialAsync(int id, [FromBody] JsonPatchDocument<TEntity> patchEntity)
{
var entity = await _service.ReadAsync(id, false);
if (entity == null)
return NotFound();
try
{
patchEntity.ApplyTo(entity, ModelState);
}
catch(Exception ex)
{
return Ok(ex.Message);
}
entity = await _service.UpdateAsync(id, entity);
return Ok(entity);
}
When accessing this in PostMan, the return is an error, patchEntity has one Operation with all values being null.
Any ideas?
|
|
|
|
|
thewizardoftn wrote: the return is an error
Are we supposed to guess what the error is?
thewizardoftn wrote:
return Ok(ex.Message); Returning an "OK" response for an exception seems like a particularly bad idea.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You didn't check if patchEntity was null before dereferencing it.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
i got error when i want to add sql server in visual studio 2019
Unable to add data connection. Could not find any resources appropriate for the specified culture or the neutral culture. Make sure -Microsoft.VisualStudio.Data.Providers.SqlSetver.SqlViewSupp ort.xmr was correctly embedded or linked into assembly Microsoft.VisualStudio.Data.Providers.SqlServer at compile time, or that all the satellite assemblies required are loadable and fully signed.
|
|
|
|
|
This is exactly the same question as the one below. And if both of those accounts belong to you, you should delete one of them.
|
|
|
|
|
In Visual studio 2019, when opening the database, the program displays the message:
Could not find any resources appropriate for the specified culture or the neutral culture.
Make sure "Microsoft.VisualStudio.Data.Providers.SqlServer.SqlViewSupport.xml" was correctly embedded or linked into assembly
"Microsoft.VisualStudio.Data.Providers.SqlServer" at compile time,
or that all the satellite assemblies required are loadable and fully signed.
Can anyone advise me how to solve this problem?
Well thank you
|
|
|
|
|
|
Hi all, how can I add the x clear button to textbox controls on a web page ? I've googled and only see references to Telerik - is this doable without third party controls ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
The browser will do it if you use type="search" instead of type ="text". Otherwise, I believe you'll have to write your own css and JS to do it.
There's probably examples online if you want to do it custom.
|
|
|
|
|
Hi, I tried type = search but no cross - not a big deal as it's only a personal project
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
pkfox wrote: I tried type = search What browser? You do have to start typing for it to show up.
See Tryit Editor v3.6[^]
|
|
|
|
|
Hi and thanks for replying, I use Firefox, tried the link you posted and still no x
Tried it with Edge and it worked
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Yep, you're right. I thought all browsers had started doing that now but I guess not.
|
|
|
|
|
Never mind - as I said it's only a personal project - thanks again
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
My project has a complete management part and the front is just a dynamics. I have a problem. How can I solve this problem?
|
|
|
|
|
Quote: I have a problem. How can I solve this problem? How could anyone here possibly answer such a question?
|
|
|
|