How can I pass an authentication header in the Image component

Vinicius Veras dos Santos 1 Reputation point
2022-11-16T06:45:22.987+00:00

My images are in a protected url. How can I pass an authentication header in the Image component?

<Image HeightRequest="50" WidthRequest="50">
<Image.Source>
<UriImageSource Uri="http://localhost/api/produtos/9676151a-6ebd-4331-8540-17f04ebf6ee6" CacheValidity="10:00:00:00" />
</Image.Source>
</Image>

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,726 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 33,176 Reputation points Microsoft Vendor
    2022-11-17T05:53:41.117+00:00

    Hello @Vinicius Veras dos Santos ,

    It is not supported in ImageSource currently. You could try to download the image file then load it.
    There are several threads discussed about this issue and a feature request at GitHub, you can see Allow custom headers to be used when ImageSource is a URI · Issue #1843. And you can follow the progress at MAUI Repro: set an HTTP user-agent header when downloading images · Discussion #11329 or create a feature request at https://github.com/dotnet/maui
    (You can check the forum posts, there are several solutions, and some developers use a third-party library. I cannot recommend you using any third-party tools due to the policy)

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.