asp.net with vue js FsLightbox lybrary Access to XMLHttpRequest origin has been blocked by CORS policy

diaaaldin qosa 0 Reputation points
2024-07-31T21:15:10.8666667+00:00

asp.net with vue js FsLightbox lybrary Access to XMLHttpRequest at 'https://localhost:44347/CarImages/3e0da2fa7fd0417ea2e2f4678229e264Logo.png' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. error

when use FsLightbox library show this error , im use this images path in another slider its run good and im use another images from internet to FsLightbox also run good this problem just appear when use my images paths with FsLightbox !!??

// this is policy code from program.cs 

builder.Services.AddCors(options =>
{
    options.AddPolicy(name:"MyAllowSpecificOrigins",
       builder =>
       {
           builder.WithOrigins("http://localhost:5173")
            .AllowAnyMethod()
            .AllowAnyHeader()
            .SetIsOriginAllowedToAllowWildcardSubdomains();
       });
});

/////////////////////

// this in vue js FsLightbox like documntation
Developer technologies ASP.NET ASP.NET Core
Microsoft 365 and Office Development Office JavaScript API
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2024-07-31T22:07:13.5866667+00:00

    In ASP.NET Core the static file handler returns static files like images. One option is to configure the static file handlers. I found the following article when doing a Google search for static file handler core and CORS.

    https://www.bytefish.de/blog/aspnetcore_static_files_cors.html

    Another option is to craft a controller to return a file stream.

    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.