Home fetch returns 401, but able to view the JSON fine through a browser window
Reply: 0

fetch returns 401, but able to view the JSON fine through a browser window

user1119
1#
user1119 Published in June 19, 2018, 6:28 pm

Fetch is returning 401 errors when trying to read a controller. However, I am able to navigate to the controller URL and see the json fine. The website has anonymous access disabled, and windows authentication enabled on the root. The issue occurs on localhost or live.

Fetch Code

(Polyfill https://www.npmjs.com/package/whatwg-fetch)

fetch("/api/letters")
    .then((data) => {
        return data.json();
    })
    .then((json) => {
        this.setState({
            items: json
        });
    }); 

LettersController

'----------------------------------------------------
'GET: api/letters
'----------------------------------------------------
'.
'.
'.
Function GetLetters() As IHttpActionResult

    Return Ok(db.Test.Where(Function(X) X.username = Modules.User.Username)

End Function

User Module

Public ReadOnly Property Username As String
    Get
        Return HttpContext.Current.User.Identity.Name
    End Get
End Property
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.242324 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO