1

In a Web-Application, written in C# in .NET Core 3.1, i want to Display a Datatable of all the Blobs in one of our Company's Azure Blob Storages. For this i'm using Datatables.net in the Frontend with Ajax-Calls which target a selfwritten API in the same Web-App. The API should get all the searched Blobs, format them for easier viewing and then give them back to the Table. Locally it really works like a charm. However, soon after deployment i noticed that the Ajax-Call just simply returns a 404 Response.

For reference:

My API-Controller

[Route("Blob/api/[controller]")]
[ApiController]
public class BlobsController : ControllerBase
{
    private readonly string _connectionString;
    private readonly string _container;
    private readonly BlobContainerClient _client;


    public BlobsController(IConfiguration configuration)
    {
        IEnumerable<IConfigurationSection> _blobStorageSection = configuration.GetSection("BlobStorage").GetChildren();
        _connectionString = _blobStorageSection.Single(e => e.Key == "ConnectionString").Value;
        _container = _blobStorageSection.Single(e => e.Key == "ContainerName").Value;
        _client = new BlobContainerClient(_connectionString, _container);
    }

    [HttpGet("{EncodedDelimiter}/{EncodedPrefix}")]
    public ActionResult GetBlobs(string EncodedDelimiter, string EncodedPrefix)
    {
        if (! StorageIsAvailable())
            return NotFound();

        string Delimiter = WebUtility.UrlDecode(EncodedDelimiter);
        string Prefix = WebUtility.UrlDecode(EncodedPrefix);

        Pageable<BlobHierarchyItem> BlobHierarchy = _client.GetBlobsByHierarchy(delimiter: Delimiter, prefix: Prefix);

        return Ok(EnrichBlobList(BlobHierarchy));
    }

    [HttpGet("init/{EncodedDelimiter}")]
    public ActionResult Initialize(string EncodedDelimiter)
    {
        if (! StorageIsAvailable())
            return NotFound();

        string Delimiter = WebUtility.UrlDecode(EncodedDelimiter);

        Pageable<BlobHierarchyItem> BlobHierarchy = _client.GetBlobsByHierarchy(delimiter: Delimiter);

        return Ok(EnrichBlobList(BlobHierarchy));
    }

Here the Ajax-Call Snippet

 var Table = $("#BlobTable").DataTable({
        ajax:{
            url: "api/Blobs/init/%2F",
            dataSrc: ""
        },
        processing: true,
        columnDefs:[
            {
                "targets": 0,
                "data": "standartizedName",
            },
            {
                "targets": 1,
                "data": null,
                "render": function(full){
                    return renderTyp(full);
                },
                "width": "10%"
            },
            {
                "targets": 2,
                "data": null,
                "render": function(full){
                    return renderDatum(full);
                },
                "width": "15%"
            },
            {
                "targets": 3,
                "data": null,
                "render": function(full){
                    return renderAction(full);
                },
                "orderable": false,
                "searchable": false,
                "width": "10%"
            }
        ],
        order:[[1, "desc"]],
        pageLength: 50

    });

And bc i have seen similar Problems where the Source-Problem was in StartUp:

        public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<TestDbcontext>(options => options.UseSqlServer(Configuration.GetConnectionString("TestDB"),
            sqlServerOptionsAction: sqlOptions =>
            {
                sqlOptions.EnableRetryOnFailure(
                maxRetryCount: 10,
                maxRetryDelay: TimeSpan.FromMinutes(5),
                errorNumbersToAdd: null
                );
            }));

        if (Env.IsDevelopment())
        {
            UseFakeAuthenticationAndAuthorization(services);

            //UseAuthenticationAndAuthorization(services, Configuration);
        }
        else
        {
            //UseFakeAuthenticationAndAuthorization(services);

            UseAuthenticationAndAuthorization(services, Configuration);
        }



        services.AddControllersWithViews();

        RepositoriesTestGUI(services);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Home}/{id?}");
        });
    }

Has someone else an Idea what could be the Problem? An API-Call is an absolute Necessity since the Storage contains 70k Files

EDIT:

By Request here are the Network Details

NetworkDetails

Bc this is my first Post i can't put embedded Pictures in apparently

1 Answers1

0

The root cause of this problem is not having permission to access. The easiest way to test is to change the access level to Container.

enter image description here

My test steps:

Access a picture in container( Blob or Container access level ).

Uri like:

https://testaccount.blob.core.windows.net/testblob/SignalR.png

Result

enter image description here

Access a picture in container( private access level ). We will reproduce the issue.

enter image description here

Suggestion

We can write a method to generate sas token to access the files. You can refer my code or read the official doc.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • 1
    I see, i will test your Solution tomorrow – Gandolf_Bengsston May 26 '22 at 07:05
  • @Gandolf_Bengsston I am waiting for your good news. – Jason Pan May 26 '22 at 07:06
  • I tried it but it sadly didn't work. Again, the app works fine in localhost but can't access the Blob-Methods of the API as soon as its deployed in an Azure-App-Service. I also made a test-method which just returns strings to see if thats a general Problem of the API but that Method works fine locally and deployed. Really getting bit bummed now. Can't seem to find the Problem – Gandolf_Bengsston May 27 '22 at 07:04
  • @Gandolf_Bengsston Could you show us the network details in broswer like me the last picture? I want to determine if the 404 is returned by backend, or is it returned after the front-end control fails to render ? Tks – Jason Pan May 27 '22 at 08:46
  • I Updated the original Post to include a screenshot of the Network Details. Sadly i can't embed Pics into Posts yet since this is my first Post. – Gandolf_Bengsston May 27 '22 at 12:37