Using Blazor wasm I can't access content-disposition response header

Viewed 280

Using Blazor I am making an API call which returns an Excel file, I am trying to access the content-disposition response header which I can see is present using Chrome dev tools :

content-disposition: attachment; filename=report-285-20200603183055.xlsx; filename*=UTF-8''report-285-20200603183055.xlsx

I am using this code but it returns false :

if (httpResponseMessage.Headers.TryGetValues("content-disposition", out IEnumerable<string> extractedHeaders))

How can I access the content-disposition value, I want to extract the filename out? Just to add, I am exposing the header in Startup.cs ConfigureServices() in the API project :

            services.AddCors(o => o.AddPolicy("CorsPolicy", builder => {
            builder
            ...
            .WithExposedHeaders(new string[] { "Location", "location", "Content-disposition","content-disposition" })    
2 Answers

You have to use

Response.Content.Headers

To get that header, Response.Headers does not contain it

Related