Reputation: 1006
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" })
Upvotes: 2
Views: 766
Reputation: 3872
You have to make sure that your API CORS policy exposes the header. See this question: Blazor WASM C# .NET 6 Content-Disposition is not Accessible
Upvotes: 1
Reputation: 340
You have to use
Response.Content.Headers
To get that header, Response.Headers does not contain it
Upvotes: 1