Search Posts


returning null in ASP.Net api from angular4

I literally spent all day to try to find out the solution and none of existing solutions to similar problems, seem to work on my problem even though the problem seems to be the quite similar…. I am doing a POST from angular4 to .net server but the server returns null. server [HttpPost] public string callBcknd([FromBody]string body) { try { Log.Info(string.Format(“{0}”, body)); } catch(Exception ex) { return “error”; } } } angular *note that I […]

http://localhost:65140/api/Students/18 405 (Method Not Allowed) Response for preflight has invalid HTTP status code 405

This is my HTTP delete method removeUsers(id){ this.header = new Headers({ ‘Content-Type’: ‘application/json’, }); this.header.append(‘Accept’, ‘application/json’); this.header.append(‘Authorization’, ‘if token’); this.header.append(‘Access-Control-Allow-Origin’,’*’); this.options = new RequestOptions({ headers: this.header }); this.http.delete(‘http://localhost:65140/api/Students/’ + id, { headers: this.header }) .subscribe( data => { console.log(data) this.details = data.json(); }, // Errors will call this callback instead: err => { console.log(err); } ); } Source: AngularJS

How Authorization Token Works?

I am trying to understand how the Token system works between Web api and Angular JS for the authentication purpose. Please correct me if I am wrong. The token is stored in a database table and add the token manually on our client application to accompany every request we make from the client. Thanks. Source: AngularJS

AngularJS httpInterceptor set Date Header Value

Below code is my $http Interceptor Factory. In this code, I have set date header value to current date at config.headers.Date but it is showing null in Asp.Net WebApi Request Header Class. How can I set Date Header value to get Local DateTime value from client. ‘use strict’; define([‘appconfig’], function (app) { app.factory(‘authInterceptorFactory’, [‘$q’, ‘$location’, ‘localStorageService’, function ($q, $location, localStorageService) { var authInterceptorServiceFactory = {}; var _request = function (config) { config.headers = config.headers || […]

Upload file and form data to server using AngularJS and Web API

I am trying to upload file and form data to server using Angular and Web API.I am using the following code. Service: App.factory(‘myService’, [‘$http’, function ($http) { return { uploadFile: function (url, file) { return $http({ url: url, method: ‘POST’, data: file, headers: { ‘Content-Type’: undefined }, transformRequest: angular.identity }); }, otherFunctionHere: function (url, stuff) { return $http.get(url); } }; }]); Controller $scope.uploadFile = function() { var fileInput = document.getElementById(‘fileInput’);; if(fileInput.files.length === 0) return; […]

Odata with and angularjs

I am following up in the course AngularJS Front to Back with Web API using, we are trying to do queries using ODATA so i added this code in the ProductController in the WebAPI // GET: api/Products [EnableQuery()] public IQueryable<Product> Get() { var productRepository = new ProductRepository(); return productRepository.Retrieve().AsQueryable(); } then added the below code in the productcontroller in the angular code: function ProductListCtrl(productResource) { var vm = this; productResource.query({$skip:1, $top:3}, function (data) { […]

NPOI Excel file download corrupt

I am trying to export data from a data table to excel using NPOI, angular2 and web API. The steps I am following are – 1. Write data from data table to XLSX and store the file temporarily on the server, 2. Read this same and into a memory stream and return. I see that browser prompts the user to download the file, once the file is downloading I get an error saying the file […]

Can’t find role when adding user to role in Asp.Net API Controller?

So, just when I finally thought I had understood the Microsoft Asp.Net Identity Role System … I run into a new problem… I have a working controller that does my role management but I had problems in the view so I decided to use angularjs for my Web-Apps Admin-Panel. Everything seemed to work after a bit of hacking but now I’m at a point that I don’t understand at all. My process: Admin presses a […]

Next Page »