Using Azure SignalR invalid negotiation response received - azure

I am currently trying to use Azure SignalR in my Blazor app but I am currently experiencing difficulties which what looks like authentication errors.
I have set it up in my Program.cs file to include the Azure SignalR:
builder.Services.AddSignalR().AddAzureSignalR();
I have then added my connection string into the appsettings.json which is validated as when running the application I get the following message:
Hub is now connected to '(Primary)xxx.service.signalr.net')
I have mapped my hub within my Program.cs
app.MapHub<MessageHub>('/messagehub');
However when I try to connect to the hub I get the following issue:
Invalid negotiation response received.
I believe this to be me having authentication within my application and this error is being produced as a result of an unauthenticated error.
However, how can I authenticate with Azure and use that hub?

I have followed the MSDOC to use Azure SignalR services in Blazor App.
I hope you followed the same way. If not follow the below workaround
use latest Microsoft.Azure.SignalR package in your application
I have added the connection string of azure SignalR in a appsettings.json file
"Azure": {
"SignalR": {
"Enabled": true,
"ConnectionString": "<SignalR Connection String>"
}
},
# use ServerStickyMode to avoid Inconsistent UI state management. If you are using many servers
"Azure:SignalR:ServerStickyMode": "Required"
I am using endpoints to Map the Hub.
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/Fallback page");
endpoints.MapHub<YourHub>('/YourHub');
});
Add the Azure SignalR service in a ConfigureServices
public void ConfigureServices(IServiceCollection services) {
services.AddSignalR().AddAzureSignalR();
...
}
After configuring these you can be able to authenticate your hub.
If still facing issue add the below line of code in your ConfigureServices to know the detailed error.
services.AddSignalR(
s =>
{
s.EnableDetailedErrors = true;
});
Refer SO thread for similar kind of issue

Related

Azure Static Web App - Function App API - How to load IOptions?

Everything is working locally still using storage in Azure. The local settings file to load the IOptions are:
"StorageOptions": {
"ConnectionString": "...xxx..."
}
The static web app is hitting the API and getting a 500 error due to not being able to load the connection string settings from the application settings. Other API calls that do not use Azure storage are working as expected.
I am unable to save the static web app settings in the normal manner of StorageOptions:ConnectionString with the specified value.
Can API settings for Azure static web apps use the IOptions pattern? If yes, how should the application settings be added in Azure to load the IOptions properly?
The static web app is hitting the API and getting a 500 error due to not being able to load the connection string settings from the application settings.
Application settings for the static web app does not allow for ":" in the setting name. So, instead of using "StorageOptions:ConnectionString" it would be "StorageOptions__ConnectionString" for the hierarchical data binding.
Noted here in step 4 of "Configure app settings": https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal
If yes, how should the application settings be added in Azure to load the IOptions properly?
I found an issue in the SO 70461295 where user #HariKrishna and #GaryChan given that the Application Settings are available only for the Azure Static Web App associated backend APIs.
If using dependency injection for configuring the application settings through Azure Static Web Apps - Azure Functions Context, then Option pattern is available which is returned when the functionality is required.
Your given format of Application Settings:
"StorageOptions": {
"ConnectionString": "...xxx..."
}
Then, you have to configure inside the Startup.Configure method such as:
builder.Services.AddOptions<StorageOptions>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection("StorageOptions").Bind(settings):
});
Updated Answer:
 As #BretOoten mentioned that the hierarchical data binding in azure static web apps configuration is possible with double underscore (__), even in the azure functions the nested objects/configuration from local.settings.json file is called with the double underscore (__) as mentioned in this MS Doc.
 For example:  
"WebApp1": {
"Storage1": {
"ConnString": value
}
}  
configuration will be like: 
WebApp1__Storage1__ConnString

SignalR with Azure - Forced by Azure.SignalR service by default on release configuration versus debug configuration (.net core 3.1)

I have setup an App and deploying using Azure. If I deploy and connect to the Azure SignalR then it is fine, and I can manage with the Azure message limits etc. However, when I try to use the "default" SignalR from my project instead of the Azure service, the release configuration still tries to connect to the Azure one.
In my startup.cs, I am especially trying to NOT use the Azure SignalR.
services.AddSignalR();
and I have commented out this line that pointed to the Azure one:
services.AddSignalR().AddAzureSignalR("Endpoint=https://<myApp>.service.signalr.net;AccessKey=<MyKey>;Version=1.0;");
Now when I publish as a Release configuration, Azure online is trying to connect to this host:
service.signalr.net
Whilst if I publish as a Debug configuration, Azure online is connecting to the host I want:
.azurewebsites.net
Which is the one I want for now.
Am tryuing to find out which varialbe is "forcing" Azure to use his own Service.SignalR.net in release mode. Could it be some of the variable I can see on the Azure App below? or is it a setting I need to put in the Visual Studio Code?
Thx.
I believe that what you can do is something like define the env on startup to use one or another but I can't say what will be the behaviour when you will set your variables on azure.
You should try something like:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseSignalR(routes =>
{
routes.MapHub<YourHub>("/YourHub");
});
}
else
{
app.UseAzureSignalR(routes =>
{
routes.MapHub<YourHub>("/YourHub");
});
}
}

Application insights not generated for .Net core app deployed on service fabric Linux cluster

I have a .Net core application that is deployed on service fabric Linux cluster. Application insights are configured in the app.
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions
= new ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions
{
EnableAdaptiveSampling = false,
EnableQuickPulseMetricStream = false,
InstrumentationKey = "xxx"
};
services.AddApplicationInsightsTelemetry(aiOptions);
I have a controller class that has some action methods and logs the information.
[HttpPost]
public ActionResult actionMethod(...)
{
TraceLine("------------------------------------");
//some code
}
private static void TraceLine(string msg)
{
msg = $">> {DateTime.UtcNow.ToString("o")}: {msg}";
Log.Information(msg);
}
I am using Serilog, configured in appsettings.json & Program.cs
When I hit action method directly from local (without hosting it on even local sf cluster), via Postman, I see app insights getting generated and pushed to azure.
azure app insights snapshot
But when I hit the action method that is deployed on Azure service fabric I don't see any insight getting generated.
What am I missing here?
Any help is much appreciated!
Well, we need to check a few things here:
1) The app insights URL and the instrumentation key in the deployment parameter files for cluster hosted on cloud (Cloud.xml)
2) After checking the Cloud.xml, the best way is to access the log files and check what is the actual problem.
There's a description here which explains how to discover where the log files are stored.
You can use RDP to access the machine, which is explained here.
I was able to solve the issue by using Microsoft.ApplicationInsights.ServiceFabric.Native SDK in my application to log app insights.
Refer .NetCore section in ApplicationInsights-ServiceFabric on how to configure insights for service fabric application.

Events not added when hosted on Azure App Service

Creating an event using the create event API call in Microsoft Graph with the .NET SDK. This is my code:
private async Task addEvent(Event #event)
{
using(var task = Task.Run(async() => await client
.Me
.Calendars[calendarID]
.Events.Request()
.AddAsync(#event)))
{
while (!task.IsCompleted)
Thread.Sleep(200);
}
}
This is running and working as expected on my local machine and on IIS in a VM by another provider - has been for about 6 months now.
However, when this runs on an Azure App Service, it doesn't throw an exception but no events are actually created. Read-only calls to get events and calendars work, but this one just doesn't. Any ideas appreciated - maybe there's a setting in an app service?

Why does my IdentityServer4 application fail to start in an Azure WebApp hosting environment?

I’m attempting to put together a simple identity server following the directions here: http://docs.identityserver.io/en/latest/ , and the project runs locally fine, I have only created a new project, not made any modifications. Running locally it launches, and I can load the .well-known/openid-configuration endpoint with no issues.
I take this bare bones project and attempt to upload it to an azure webapp and get the attached:
HTTP Error 502.5 - Process Failure
It appears that the application fails to start in azure.
I can publish a .NET Core MVC application no problem, but with this IS4 template I always receive the process failure. What am I missing? Should this not work out of the box here?
The accepted answer is incorrect and insecure. That default code is there for a reason. During development you have a developer signing credential, for production you have to implement your own signing credential. See the following answer:
How do I configure "key material" in Identity Server 4 to use SQL, KeyVault, or any other system?
You need to change the code in Startup.cs file. If you don't run it in development environment, it will throw the exception("need to configure key material"). I just comment these code. Then it works well in Azure.
public void ConfigureServices(IServiceCollection services)
{
// uncomment, if you want to add an MVC-based UI
//services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryClients(Config.GetClients());
//if (Environment.IsDevelopment())
//{
builder.AddDeveloperSigningCredential();
//}
//else
//{
// throw new Exception("need to configure key material");
//}
}
The result:

Resources