Asp.net: 'application/grpc-web' is not supported
Asked Answered
G

2

6

I had Asp.net core and gRPC working on the browser...but now I get:

info: Grpc.AspNetCore.Server.ServerCallHandler[2]
  Request content-type of 'application/grpc-web' is not supported.

Any ideas on how to track this down?

Greyhen answered 4/12, 2020 at 2:7 Comment(5)
Have you done any changes to the project and then this started to happen or did all this just happen by it self all of the sudden?Breastplate
I believe it's because of some changes I made.Greyhen
Ok @Ray, I believe you have to give up some more info to have any chance of help..Breastplate
Wish I could've given more info that would have been useful. I was looking for more diagnostics that would point to the problem. Like listing supported content-types, etc... Anyway, I found the problem: I called app.UseEndpoints() twice is...bad?Greyhen
BTW: I've added a unit test that catches this kinda error quicker.Greyhen
E
17

Likely an issue in your Startup.cs

Yours should look something like this enter image description here

My guess is that you are missing app.UseGrpcWeb() or the EnabledGrpc() on the EndpointConventionBuilder

Estep answered 25/2, 2021 at 5:20 Comment(1)
You saved my day! The only thing that I needed to change here are cors settings and to set it like here learn.microsoft.com/en-us/aspnet/core/security/…Sports
W
9

I ran across this issue. I had my app.UseGrpcWeb(); before app.UseRouting();

It had to be after.

So correct order is:

    app.UseRouting();
    app.UseGrpcWeb();

See https://learn.microsoft.com/en-us/aspnet/core/grpc/browser?view=aspnetcore-5.0 -- "Configure gRPC-Web in ASP.NET Core"

Wuhsien answered 23/3, 2021 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.