0

I must do the simple get request for GET method. Everything do such in internet exampl. Bad have a mistake

http://prntscr.com/m3erxv

enter image description here

Cod of my js controller

var app = angular.module("appTradeRoom");
app.controller("EducationController", function ($scope, $http) {
    $scope.user = {
        email: '',
        firstName: '',
        lastName: '',
        Password: '',
    };
    $scope.register = function (){
        $http.get("/api/Education");
    };
});

Cod of my API Controller

[Produces("application/json")]
[Route("api/Education")]
public class EducationController : Controller
{


    [HttpGet]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Get()
    {

        return null;
    }



}

I have a breakpoint on Get Method but it not go there. Maby something on startup?

All link i my website goes such this

http://localhost:51489/#!/education

I did it with method .success and did it with data such post method. Nothing. Mistake - bad request

georgeawg
  • 48,608
  • 13
  • 72
  • 95
FX_Sektor
  • 1,206
  • 2
  • 14
  • 32
  • Make sure to allow cross origin requests; https://stackoverflow.com/questions/52896068/reactasp-net-core-no-access-control-allow-origin-header-is-present-on-the-r/52897036#52897036 – Felix K. Jan 05 '19 at 16:49
  • @B12Toaster CORS problems create status -1 errors. This is a status 400 error. – georgeawg Jan 05 '19 at 19:03
  • Check http response in your browsers network panel if there are additional information and your server logs. If you can't find the answer, please post full request and response as you see it in dev tools > network. – Christoph Lütjen Jan 05 '19 at 21:31
  • @georgeawg yes of course, I didn't follow the image link and missed the question is referring to a 400. Because everything else looked fine, I thought it is worth mentioning CORS as a potential error source. – Felix K. Jan 05 '19 at 22:13
  • I found a mistake. On consctructor of Api Controller. When I comented the paramentr "db" is is working, I mean parament on the moment to give the controller, not when I write it to _db http://prntscr.com/m3k10a. I dont know why, I did all evrething with my conectiong string but without result – FX_Sektor Jan 06 '19 at 00:24
  • 1
    Are you sure you're sending the CSRF token? Look up the documentation for [ValidateAntiForgeryToken]. AngularJs relies on a convention to handle CSRF. Read more here https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-2.2#angularjs – Andrew Lahikainen Jan 07 '19 at 01:43
  • Try to remove `[ValidateAntiForgeryToken]` on Get method. – Ryan Jan 08 '19 at 07:16
  • There were two mistake? and one of them was with ValidateAntiForgeryToken. But as I understand I need for security, if I have post request for register data, I need [ValidateAntiForgeryToken]? – FX_Sektor Jan 08 '19 at 07:25
  • Yes you are right but your methed is `[HttpGet]`.I tried and it return 400 when add the attribute on Get method. – Ryan Jan 08 '19 at 09:04

0 Answers0