1

I want to host simple signalR app on azure to send chat messages for my mobile/web chat application. I am lost in the jungle of that is microsofts documentation with 99% depricated examples.

Now i got the following questions:

  1. Do i need to register "Microsoft.Web" for my subscribtion or is there a cleaner way around this?
  2. What is the ASP.NET Core project template with the least overhead for my simple signalR hub (I dont need any web pages)

In my working project i used "ASP.NET Core Web App" as a starting point and hooked up a simple hub. But when i publish the app i was asked to register "Microsoft.Web" for my subscription.

! * The subscription is not registered to use namespace 'Microsoft.Web'. ! *`

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29

1 Answers1

0

About the error message you got, I think this answer already had a great explanation. Maybe we can create an Azure web app manually in Azure portal then choose this resource when publishing app in VS.

And there's no template right now in visual studio to create asp.net core signalr project. But we only need to create a Hub and register it into a web app for your requirement following this document. Creating a Hub like below:

using Microsoft.AspNetCore.SignalR;

namespace SignalRChat.Hubs
{
    public class ChatHub : Hub
    {
        public async Task SendMessage(string user, string message)
        {
            await Clients.All.SendAsync("ReceiveMessage", user, message);
        }
    }
}

Then use it in Program.cs, if you had standalone client application as the signalr client, you may need to add Cors policy.

builder.Services.AddSignalR();
...
app.MapHub<ChatHub>("/chatHub");

If you need to use Azure Signalr Service, you can have below code instead.

builder.Services.AddSignalR()
    .AddAzureSignalR(options => {
        options.ConnectionString = connection_string";
    });
Tiny Wang
  • 10,423
  • 1
  • 11
  • 29
  • Thank you for your response. Maybe my question was not clear enough but the example project uses the web app as server and also adds pages for chatting. Is it possible to cut all that code and therefore dont use the Microsoft.Web subscribtion? – Lars Stecker Apr 12 '23 at 14:21
  • thank you for your response, per my knowledge, when we need to use Azure to host the application, we can choose Azure web app including web app or console app, or we can publish to an Azure VM. And the sample in the document based on a web app doesn't mean you have to add page code like the sample, you can create your own client with other language following the document to connect to the signalr web app. So I think you have to use Microsoft.Web subscription. Or in other words, if you don't want to use MIcrosoft.Web subscription, what subscription you want to use? – Tiny Wang Apr 13 '23 at 05:33