Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Material Table causing 401 Unauthorized error if page refreshed


I have got my mat-table showing retrieved data from an httpget method in the .Net Core server side. However, when the page is refreshed or the table was initiated in the main component, I get the following error:

NodeInvocationException: Http failure response for http://localhost:5649/api/Project/GetProjectList: 401 Unauthorized

  • Component:

    selector: 'home',
    templateUrl: './home.component.html'})

    export class HomeComponent implements AfterViewInit {
    displayedColumns = ['ProjectId', 'ProjectTitle'];
    dataSource = new MatTableDataSource();

    constructor(private projectSerivce: ProjectService, private http:
    HttpClient, @Inject('BASE_URL') baseUrl: string) {
    this.URLstring = baseUrl;

    ngAfterViewInit() {
    this.projectSerivce.getProj().subscribe(data => {
    console.log("Total No: "+data.length); = data });}

  • ProjectService

    export class ProjectService {
    baseUrlH: string;
    constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
    this.baseUrlH = baseUrl

    getProj(): Observable {
    const href = this.baseUrlH + 'api/Project/GetProjectList';
    return this.http.get(href).map(Response =>

  • DataSource

    export class projDataSource implements DataSource {

    private recProj = new BehaviorSubject([]);

    constructor(private projService: ProjectService) {

    connect(): Observable {
    this.projService.getProj().subscribe({ next: (value) => {}})
    return Observable.merge(this.recProj);


  • Server Side API

    public async Task> GetProjectList()
    IEnumerable ProjectList;
    using (TAMS_DBcontext db = new TAMS_DBcontext())
    ProjectList = await db.Project.ToListAsync();
    return ProjectList;

Why the data would be successfully retrieved when I navigated to this component but would not re-initiate if page is refreshed? Also why the error would appear if the table got initiated in the main component when the app is launched?

  • Server Side: .Net Core 2.0 (Windows Authentication)
  • Front Side: Angular 5.2.3

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Material Table causing 401 Unauthorized error if page refreshed


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription