I am using Azure Blob Storage for storing and downloading files for my .net core mvc web application. I have shared the blob container as Public access.,
I am directly consuming those images, pdf inside html tags of web pages like below,
<img src="[azure_blob_img_url]" />
<embed src="azure_blob_pdf_url" />
Like this I am using to show the image inside our web app. But people can able to open this blob url directly outside our app also which is not secured.
Please give me solution, how do prevent to access the blob url outside my website domain.
I don't like to using download and return the file in my website. I want to use azure blob url directly inside html tag.
Thanks in advance!
To prevent direct access to the Azure Blob URLs outside of the website domain, you have to use
Shared Access Signaturewith a limited time span.Using
SAS token, you can control theaccess permissions and expiration timefor the URLs.Generate a SAS token with appropriate permissions (read, write, or list) for your blob container or individual blobs.
Output
Take the
blob Urland share it.You can access the blob for specific time mentioned in the above code (5mins).
The method
GetSharedAccessSignatureis used to generate aSAS tokenfor the blob with read permission and a 5-minute expiry time.