Error: Cross-Origin Request Blocked when making an AJAX request

I am currently working on two projects. The first project is an ASP.NET web project, and the second project involves an embedded HTTP server library.

The embedded HTTP server project was sourced from: embedded http server project

My goal is to enable users to save a video file from their local device to shared storage. I have been attempting to achieve this by getting and sending files from the browser using AJAX requests. The embedded HTTP server is responsible for receiving byte arrays and saving the video file to the client's shared storage. However, I have encountered a persistent issue that I have yet to resolve despite spending several days on it.

In Google Chrome, the process gets stuck at stream.CopyTo(streamReader);.

In Firefox and Internet Explorer, an error message stating "Cross-Origin Request Blocked" is displayed. Despite the error, Firefox successfully saves the file.

Below is the code snippet for the AJAX request:

[AJAX request code here]

And here is the code snippet for the embedded server to handle the request:

[Embedded server code goes here]

Additionally:

For Internet Explorer: Enabling "Access data sources across domains" in the security settings allows the process to work without errors.

For Google Chrome: Starting Chrome with the --disable-web-security parameter resolves the issue, but I am looking for a solution within the code itself.

Answer №1

It's possible that the issue lies with the client-side browser. For instance, Google Chrome is known to block cross-origin requests by default. To bypass this restriction, you can install a plugin like this one.

Answer №2

If you're looking for a solution, I discovered one that might be helpful: I came across the Nancy.Hosting.Self library from , which allowed me to utilize an embedded http server. With this tool, I successfully added "Access-Control-Allow-Origin" to response.Headers, enabling me to transfer files without any issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing window.location.reload just once within $ionicPlatform.ready [Ionic]

In the app.js file, I am initiating an OAuth Process within the device ready function using InAppBrowser. The process involves obtaining a token which is then checked to redirect to a specific view. .run(function($ionicPlatform,$rootScope,$http,jwtHelper, ...

Ways to extract a particular item from a dataset

{ type: 'Text', firstLanguage: { translation: 'When did the Constituent Assembly approve the Objective Resolution?', option_a: '14th February 1949', option_b: '12th March 1949', option ...

Vue function displays 'undefined' message

Although many posts on this topic exist already, I am struggling to understand what is going wrong (even after searching extensively here and on Google). I have created my interceptor like this, but I keep receiving an error message stating "This is undef ...

Script for converting Fixed Positioned Elements to Static

I am frequently finding that elements on web pages are causing disruptions due to their fixed positioning. I am exploring ways to disable the position: fixed CSS rules on any website I visit. To address this issue, I have developed a userscript specifical ...

The process of deleting lines from an image using Javascript

If I have an image of a data-table and I want to eliminate all the grid lines (defined as continuous vertical or horizontal pixels), is there a way to achieve this using Javascript's image data manipulation? I envision looping through a 2D array conta ...

Is there a way to change a DAT file to a PDF using C#?

Is there a way to convert a DAT file to PDF using c# without the need for a database? At the moment, I am using Crystal Report and inserting data from multiple DAT files into a database before converting it into PDF from the database table. The problem a ...

The discovery of a commitment in the statement. The automation of unwrapping promises within Angular statements has been phased out

Struggling with errors while setting up a new AngularJS project. Here is the code for my app and controller; var app = angular.module('myApp', ['localytics.directives']) .config(['$parseProvider', function ($parseProvide ...

Applying a class to a single div element

I am struggling with adding a class to a specific div only if it contains an image. <div class="large-6 columns check-Div"> <div class="custom-table"> <div class="text"> <?php echo $latestimage; ?> </div> ...

The fixed position element appears to be failing to stay fixed in Google Chrome

Something strange is happening with a fixed position element in Chrome. It is still scrolling with the page even though it should be fixed. To better understand the issue, you can view it on the live site In Firefox and even IE, the "Block 1 Block 2 Block ...

Improve the speed and efficiency of transitioning to the next page by utilizing .tif images

I am currently using WinForms to develop an application that involves working with large .tif images with multiple pages. The open and next buttons in my forms are used to navigate through these images displayed in a picturebox. However, I have noticed som ...

A guide to saving an ArrayBuffer as a file using JavaScript

I am currently developing a file uploader for the Meteor framework. The approach involves breaking down the file on the client side from an ArrayBuffer into small packets of 4096 bits, which are then sent to the server through a Meteor.method. The abridge ...

What are the steps for executing a program with c#?

Is there a way to launch a software knowing only its name? Process software = new Process(); software.StartInfo.FileName = "winword.exe"; software.Start(); The code above is expected to open Microsoft Word, but the challenge lies in obtaining the correct ...

Choose particular elements within an array

I am working with an array that contains certain lines I need to highlight, specifically A and B: [0] A1 [1] a line I don't need [2] B1 [3] another line I'm not interested in [4] A2 [5] yet another line I want to ignore [6] B2 [7] something else ...

Trouble with Material-UI Textfield Hinttext Functionality

When designing a textfield according to job requirements, I encountered an issue. After assigning a background color to the TextField, the hintText disappeared. To resolve this, I had to manually set the z-index of the label. Now, the hintText is visible, ...

Implementing JavaScript functionality upon page load with ASP.NET

I have come across a situation where I am trying to integrate working code (jQuery/Javascript) that makes an API call and sends data to it. The API service then responds with a success or failure message based on the data insertion into the API db. Everyth ...

Improving conditional rendering in Mui <Cards> component by fixing state behavior

I have a situation where I want to display a Floating Action Button inside each Mui card when hovered over. However, I'm running into an issue with the hover state affecting all cards instead of just the one being interacted with. How can I ensure tha ...

Double.TryParse function behaves unexpectedly when handling thousand separators

Today, I encountered something truly bizarre and couldn't help but wonder if I had overlooked something. As I attempted to convert a string (with thousand separators) into a double value, I stumbled upon the following peculiar issue. CultureInfo ci ...

An issue arises when attempting to utilize URL parameters within a loader

In my React project, I am utilizing React-Router. The code for my movie page is as follows: import React from "react"; import axios from 'axios' export async function loader({ params }) { const movieId = params.movieId; const mov ...

Encountering an error while trying to implement a React Higher Order Component (HOC): the type provided is invalid – it should be a string or a

Today marks my first experience using Flow in a professional setting, as I typically lean towards TypeScript over Flow. I am encountering an issue while trying to create a simple HOC (Higher Order Component), something I have done numerous times without a ...

Sorting in GridView is malfunctioning when set to ascending order

I am facing an issue with my GridView that has sorting enabled. When there is a single page of results, both ascending and descending sorting works correctly. However, when there are multiple pages, only descending sorting works consistently. The ascendi ...