SignalR Negotiate 404 on Subdomain - c#

I've created a small MVC SignalR app which I'm having trouble running on my server under a subdomain:
http://chat.mydomain.com, which maps to a folder called /chat.
I've also made a console program using SignalR Client which connects and works perfectly, strangely enough.
The error from the MVC app is a 404 from http://chat.mydomain.com/chat/signalr/negotiate?clientProtocol=[...]. I can see why this is happening but have no idea how to fix it. In my generated hubs file, the line
signalR.hub = $.hubConnection("/chat/signalr", { useDefaultPath: false });
is technically correct, but should read $.hubConnection("/signalr", { useDefaultPath: false });
Any ideas on how to alter this? Or should I just use the raw connection API.
Also why does it work properly from the console app?
Thanks in advance.

You can continue to use the generated hubs file. You just need to modify the hubConnection's url (which stored at $.connection.hub.url) before you start your SignalR connection.
// This is initially set to "/chat/signalr" as specified in the hubs file
$.connection.hub.url = "/signalr";
$.connection.hub.start()...

Related

401 Unauthorized when querying durable function status

I need some help with Azure Durable Functions.
I created a new durable function with VS Code in C# and deployed it to Azure via the VS Code azure function extension. The function app resource was already created manually in the portal. I use
FUNCTIONS_WORKER_RUNTIME: dotnet
FUNCTIONS_EXTENSION_VERSION: ~2
I can trigger the creation of an durable task and but when I query the status with the statusQueryGetUri, I only get a 401 Unauthrized. The http trigger of the function itself is anonymous and does not require authentication (for debug purpose only).
The requests look like this (I used Postman to send the requests):
HTTP POST https://{function-app}.azurewebsites.net/api/SayHello_HttpStart
Response:
{
"id": "da3259a462084e86a34f8ce9859a6ed6",
"statusQueryGetUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"sendEventPostUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6/raiseEvent/{eventName}?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"terminatePostUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6/terminate?reason={text}&taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"rewindPostUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6/rewind?reason={text}&taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"purgeHistoryDeleteUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g=="
}
The Get Request is then simply:
GET https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==
Did I miss some configuration I have to set to allow access to the uri? What logs might help me figure out what the problem is?
When I run the code locally there are no problems and everything works as expected.
Thanks a lot for all help!
Note that the statusQueryGetUri is an admin endpoint which always requires a System Key.
GET <rootUrl>/runtime/webhooks/durabletask/instances/<GUID>
?taskHub={taskHub}
&connection={connection}
&code={systemKey}
As an alternative, you could also set the x-functions-key header of the http request with this key.
More info on the usage of the HTTP endpoints in the docs.

Cannot reach an otherwise reachable web API, with dots in URL

I have a web service deployed on IIS 8.5 (Windows Server 2012 R2) which has to be called passing four arguments. They are not optional, and are to be included directly in the URL, without a query string, as such:
.. api/myservice/argument1/argument2/argument3/argument4
If I try to call it with the URL written above, it answers and gives the expected response. However, a 404 - Not Found error is given instead when trying to use real production-like arguments as such:
api/myservice/AAAA_AAAAA.AAA_AAA_AA_AA_AAA_000000_000000_000000/333/AAA/AAA.AAA.AA.AA.AAA.000000.000000.000000
I thought the multiple dots raised the issue, so I replaced each one of them with %2E, but nothing changed.
I've searched for already answered questions: I tried this and this, to no avail.
What is the problem with that production-like URL?
Here is the code of the API:
[RoutePrefix("api/myservice")]
public class MyServiceController : ApiController
{
[HttpGet]
[Route("{argument1}/{argument2}/{argument3}/{argument4}")]
public string StartValidation(string argument1, string argument2, string argument3, string argument4)
{
// operations...
}
}
I traced the request with IIS Failed Request Tracing as suggested in an answer, but I'm not able to find a clue in the resulting log:
Can anyone help me?
Enable failed request tracing on IIS to check.
https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/tracefailedrequestslogging
Good possibility that IIS is rejecting these as part of URLScan (if enabled), but FRT will confirm.
First try to deploy it to your local Iis, if it works, means that your production can have a different configuration at the level of the IIS, or the compiled code is not the same as the one you have and you need to redeploy the api.
If the api fails at the level of your local IIS and it runs properly from the vs(if you pass any parameter with the postman) you hit a backend breakpoint, then you have a wrong configuration on your deployment on your local IIS.
If you never hit the breakpoint you have an error at the level of your code.
Hope this helps
I finally solved this. I added a piece code, provided by this answer to a quite identical question, to the web.config, but a different issue arose: it seemed IIS had to be run in "Integrated Mode". Thanks to the clue given by this answer to a question about this subsequent problem, I switched the Managed pipeline mode of the application pool where the API was deployed from Classic to Integrated, which allowed that code to work. The web API finally accepts arguments with periods.

Why cant i use serveo instead of ngrok to tunnel connection to a mvc application hosted on EC2 server for receiving SMS on Twilio

I have a simple asp.net mvc web application which listens for a message and replied back with a standard response. It uses the Twilio API and in
Here is the code:
// Code sample for ASP.NET MVC on .NET Framework 4.6.1+
// In Package Manager, run:
// Install-Package Twilio.AspNet.Mvc -DependencyVersion HighestMinor
using Twilio.AspNet.Common;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;
namespace WebApplication1.Controllers
{
public class SmsController : TwilioController
{
public TwiMLResult Index(SmsRequest incomingMessage)
{
var messagingResponse = new MessagingResponse();
messagingResponse.Message("The copy cat says: " +
incomingMessage.Body);
return TwiML(messagingResponse);
}
}
}
For the code to run, Twilio suggests me "While there are a lot of ways to do this, like deploying your application to Azure or AWS, you'll probably want a less laborious way to test your Twilio like ngrok to allow Twilio to Talk to Your ASP.NET Application"
I have used ngrok, which allows me to expose my local environment to the whole public internet which can then be accessed by URL provided by ngrok,
but the free version keeps changing the subdomain whenever I restart my ec2 server (thus restarting the ngrok tunnel).
What I would like to know is I tried an alternate called serveo which allowed me to chose a subdomain for free, but the URL generated it given an error (400) when I send a message to Twilio.
Is there a way around? I m new to the world of asp.net mcv web application and Twilio and would really appreciate some guidance.
I just need this code to keep running so that it can listen for SMS and respond back.
If not, How can I deploy it on AWS? Which would provide me with an URL to feed to the Twilio's console
The reason 'serveo' isn't working is because (I believe) you are using IIS Express which doesn't allow requests with host header's other than localhost.
'ngrok' has a way around that, as does our free VS Extension called Conveyor. Conveyor at the moment has tunnelling in beta, but it is stable and subdomains are fixed. You can download it from the Extensions menu in VS or marketplace. Here's a tutorial for Twilio https://conveyor.cloud/Help/Writing_webhooks_on_localhost_with_Visual_Studio_and_IIS_Express

Azure Notification Hubs Register Device Error 404

This is the first time I'm using Azure Notification Hubs and I'm having some trouble getting it working properly with my application.
The part I'm stuck on (at the moment) is registering my device with the notification hub. I'm using the backend method to do the registration ... that is, I'm creating an Installation object and using the CreateOrUpdateInstallationAsync method to register the device via my Web API. I'm only testing it at this stage so I'm hitting my API endpoint with dummy data via Postman.
When I step through my code, I'm getting the following error when I execute CreateOrUpdateInstallationAsync ...
The remote server returned an error: (404) Not Found. Entity does not
exist.TrackingId:203cba37-007d-4dcb-ae25-ced33fa012aa_G1,TimeStamp:2/4/2018
10:24:02 PM
I've tested that I am connecting to the Notification Hub correctly by calling GetAllRegistrationsAsync. This returns an empty list (expected) and no error ... so I have my endpoints set up correctly. I'm wondering if there is a problem with my dummy data? For the installation Id, I've just created a random GUID (Guid.NewGuid). The Device ID and Push Notification Handle are random numbers and letters. And I'm testing this for the Android platform (NotificationPlatform.Gcm).
Has anyone seen this error before and know what it means? Am I able to just use random data for testing purposes (I'm only interested in registering devices at this stage) or do I need legitimate data (real device id's, etc)?
Thanks in advance.
The CreateOrUpdateInstallationAsync method would essentially invoke the REST API Create or Overwrite an Installation. When you register with a notification hub from your custom backend using the Installation, the core code would look like as follows:
NotificationHubClient hubclient = NotificationHubClient.CreateClientFromConnectionString(listenConnString, hubName);
await hubclient.CreateOrUpdateInstallationAsync(installation);
Note: You could install the Microsoft.Azure.NotificationHubs package for back end operations.
For a simpler way, I just created a console application and test this operation as follows:
Note: I just created a new Azure Notification Hub and did not set any notification settings. And I set a GUID as the InstallationId and a random string as the PushChannel, the rest operation could work as expected.
And I could retrieve the previous added registration as follows:
Has anyone seen this error before and know what it means? Am I able to just use random data for testing purposes (I'm only interested in registering devices at this stage) or do I need legitimate data (real device id's, etc)?
The operation could work on my side, I would recommend you debug your application and leverage fiddler to capture the network traces to narrow this issue. Moreover, you could follow Registration management for more details about registering devices with azure notification hubs.
Ok, it turns out that I had the wrong value for Hub Name when instantiating the NotificationHub object using NotificationHubClient.CreateClientFromConnectionString. I was using the namespace, instead of the hub name (visible on the Overview tab in the Azure Portal).

C# SOAP with a custom URL

Okay, simple situation: I'm writing a simple console application which connects to a SOAP web service. I've imported a SOAP Service reference and as a result, my application has a default endpoint build into it's app.config file.
The web service, however, can run on multiple servers and the URL to the proper web service is passed through the commandline parameters of my application. I can read the URL, but how do I connect the web service to this custom URL?
(It should be very simple, in my opinion. It's something I'm overlooking.)
Is this using an auto-generated class deriving from SoapHttpClientProtocol? If so, just set the Url property when you create an instance of the class.
Well, .NET can provide some very useless error messages sometimes. In IIS, the service was configured to AutoDetect cookieless mode. As a result, I had to append "?AspxAutoDetectCookieSupport=1" to the URL. Although that would fix the problem, it was just easier to go to the IIS console, open the properties of the service, go to the ASP.NET tab page, click the "Edit configuration" button, to to "State Management" in the newly popped up screen and change "Cookieless mode" into something other than "AutoDetect"...
Excuse me. Dumb error. Am going to hit myself on the head a few times for this. ;-)
As Jon said, you set the Url, as in:
Namespace.ClassName nwe = new Namespace.ClassName();
nwe.Url = "http://localhost/MyURL/site.asmx";

Categories