0

My application GETs the pages from a website and displays them in a localhost domain. but on specific websites (like habr) I receive a message like so: devtools console

the code which does all the stuff:

app.Run(async (context) =>
{
    var url = context.Request.GetDisplayUrl()
        .Replace(@"https://localhost:5001", "");
    var request = (HttpWebRequest) WebRequest.Create(@"https://habr.com" + url);
    var responce = (HttpWebResponse) request.GetResponse();
    var resStream = responce.GetResponseStream();
    var reader = new StreamReader(resStream);
    await context.Response.WriteAsync(await reader.ReadToEndAsync());
});

and the CORS:

app.UseCors(builder =>
{
    builder.DisallowCredentials();
    builder.AllowAnyHeader();
    builder.AllowAnyMethod();
    builder.AllowAnyOrigin();
});

I've tried without DisallowCredentials, but it didn't help. Tried to proxy StackOverflow, and it worked fine.

Connor Low
  • 5,900
  • 3
  • 31
  • 52
savva
  • 11
  • 3
  • Does [this](https://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-core) answer your question? – Gleb Sep 01 '21 at 17:30
  • no, it doesn't. As you can see, i tried setting CORS to allow everything. – savva Sep 01 '21 at 17:36
  • Are you calling `app.UseCors` before or after `app.UseMvc`? – Gleb Sep 01 '21 at 17:43
  • i'm not using MVC. I just need to proxy a website via my localhost domain. Or MVC is required here? – savva Sep 01 '21 at 17:52

1 Answers1

0

That error is telling you that your app, https://localhost:5001, cannot access the proxied target destination, ...marketing/?page. This is not a problem that can be solved by setting your own CORS policy: it's the target's CORS policy that is restricting the access.

In other words, your localhost app is making an XMLHttpRequest to a destination that revokes the connection for violating their CORS policy.

Connor Low
  • 5,900
  • 3
  • 31
  • 52