Blazor Web assembly project with prerendering and accessing data through Grpc is not running in local IIS server

Posted 107 days ago by Keerthi
Edited 106 days ago
0

I have two simple web assembly projects having Grpc service in the following links.
without pre-rendering
with pre-rendering

Both the solutions work fine when run in Visual studio. However, when each of the solutions is published and hosted through the local IIS server, the one without pre-rendering is working fine but the other is not.

Error in brief:
RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. Http2ConnectionException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1).", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.Net.Http.Http2ConnectionException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1).
at System.Net.Http.Http2Connection.ThrowProtocolError(Http2ProtocolErrorCode errorCode) in System.Net.Http.dll:token 0x60005f3+0x6
at System.Net.Http.Http2Connection.ReadFrameAsync(Boolean initialFrame) in System.Net.Http.dll:token 0x60005bc+0x1ea
at System.Net.Http.Http2Connection.ProcessIncomingFramesAsync() in System.Net.Http.dll:token 0x60005bd+0x93

 

For more details please visit this link

  • 0

    Does it work if you switch your project to use a secure https connection?

    Posted 106 days ago by selliott
  • 0

    Yes, I'm already using a https connection (using a self-signed certificate) in its bindings.

    Posted 104 days ago by Keerthi Edited 104 days ago
  • 0

    This seems to be related to your app not using a secure base address. When I adjust your Startup.cs file and hard code your base address (line 48), it works.

    string baseAddress = "https://localhost:44328/"; // addressFeature.Addresses.First();
    Posted 104 days ago by selliott
  • 0

     Did you try hosting the pre-rendered solution in your local or remote IIS?

    When I try to hard code the URL of the server in IIS (https://testserver.com/) the get the following error. I'm trying to make my invalid certificate valid to get rid of this exception.

    An unhandled exception occurred while processing the request.

    RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
    ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch
    at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception) in System.Net.Security.dll:token 0x60002e7+0x35
    at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm) in System.Net.Security.dll:token 0x60002e4+0x608
    at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600056c+0x95
    --- End of inner exception stack trace ---

    Posted 104 days ago by Keerthi
  • 0

    I was running on local IIS. I noticed in your screenshot at the GitHub link in your original post that your security certificate wasn't setup properly, since your browser was displaying the "Not Secure" notice. I suspect the hard-coded approach will work once you have your certificate setup properly.

    Posted 104 days ago by selliott
  • 0

    can you please help me understand why the project with pre-rendering needs to have an authorized certificate to run in the IIS whereas the same project that is not pre-rendering does not need it?

    Posted 104 days ago by Keerthi
  • 0

    unfortunately, I cannot add a trusted certificate to my local machine. So I added a trusted certificate provided by my organization in the remote server IIS, and I still get the initial exception. If I hard code the base URL address then the error says: Error starting gRPC call. HttpRequestException: No connection could be made because the target machine actively refused it.

    Can you please provide a repo of the code that you are pre-rendering and able to host it in the IIS server using Grpc call?

    Posted 103 days ago by Keerthi
  • 0

    I used your repo HERE.

    I adjusted your ConfigureServices method of your Startup.cs file to this to get it working without hard-coding the Uri:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllersWithViews();
        services.AddRazorPages();
         ervices.AddGrpc();
        services.AddScoped<HttpClient>(sp =>
        {
             // Get the address that the app is currently running at
            var uriHelper = sp.GetRequiredService<NavigationManager>();
            string baseAddress = uriHelper.BaseUri;
            return new HttpClient { BaseAddress = new Uri(baseAddress) };
        });
    
        services.AddScoped(services =>
        {
            var uriHelper = services.GetRequiredService<NavigationManager>();
            string baseAddress = uriHelper.BaseUri;
            var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler());
            return GrpcChannel.ForAddress(baseAddress, new GrpcChannelOptions { HttpHandler = httpHandler });
        });
    }

    This did require adding a using directive for Microsoft.AspNetCore.Components

    As far as why it requires a secure connection when prerendered and not when rendered in the Client, I'm not sure. This is the first time I've ever messed with gRPC. I would guess it has something to do with prerendering occurring on the Server compared to it running in the JavaScript sandbox of the browser otherwise.

    Posted 103 days ago by selliott Edited 103 days ago
  • 0

    Now when I try this snippet of code and host this simple pre-rendered project in my remote IIS, there is a different error.

    RpcException: Status(StatusCode="PermissionDenied", Detail="Bad gRPC response. HTTP status code: 403")

     

    Same project when hosted in local IIS:

    An unhandled exception occurred while processing the request.

    RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
    ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch
    at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception) in System.Net.Security.dll:token 0x60002e7+0x35
    at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm) in System.Net.Security.dll:token 0x60002e4+0x608
    at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600056c+0x95
    --- End of inner exception stack trace ---

    Looks like no one has yet encountered this kind of error and not sure of any resolution steps further

    Posted 103 days ago by Keerthi Edited 103 days ago
  • 0

    I believe your best next step would be to seek out help setting up your local development environment. Mostly, it sounds like you're going to need to get a security certificate installed correctly locally. Until you rule things out related to your development environment, you're going to have too many potential causes for your errors.

    Posted 103 days ago by selliott Edited 103 days ago
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 1
An error has occurred. This application may no longer respond until reloaded. Reload 🗙