Click here to Skip to main content
15,505,126 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionMessage Removed Pin
7-Jul-20 0:46
umeshamin7-Jul-20 0:46 
AnswerMessage Removed Pin
13-Jul-20 12:39
professionaljkirkerx13-Jul-20 12:39 
Questionpls help Pin
Member 148797912-Jul-20 22:44
Member 148797912-Jul-20 22:44 
SuggestionRe: pls help Pin
Richard MacCutchan2-Jul-20 22:48
mveRichard MacCutchan2-Jul-20 22:48 
GeneralRe: pls help Pin
ZurdoDev6-Jul-20 9:10
professionalZurdoDev6-Jul-20 9:10 
AnswerRe: pls help Pin
David Mujica6-Jul-20 8:27
David Mujica6-Jul-20 8:27 
JokeRe: pls help Pin
DerekT-P7-Jul-20 3:18
professionalDerekT-P7-Jul-20 3:18 
QuestionAngular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx29-Jun-20 13:48
professionaljkirkerx29-Jun-20 13:48 
I spent all day on this. It just started happening recently.
So I package a model in Angular, and create a body of JSON using JSON.stringify(model)
Then package it all up and send it as a promise. I just noticed that the JSON quotes are escaped out with a slash, and it crashes the API. If I take the slashes out, the API accepts the JSON.

I'm not sure what to make of this, and if I should fix the client side or work on the server side with this.
I put the replace(/\/g, "") in below to test the theory that it's the slashes crashing the API. Now the API works, but I can't see this as a permanent fix.
validateTokenAsPromise(signIn: SignIn): Promise<SignIn> {
    const authUrl = this.baseUrl + "api/auth/AuthenticateAccount";
    const toSignIn = JSON.stringify(signIn).replace(/\\/g, "");    
    const httpOptions = {
      headers: new HttpHeaders({
        "Content-Type": "application/json",
        "Accept": "application/json"
      })
    };
    return this.http.post<SignIn>(authUrl, toSignIn, httpOptions).toPromise();
  }

I send it to a .Net Core controller api, and the api rejects the call, because of the data in the body.
The data has the quotes escaped out.
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]

[HttpPost("AuthenticateAccount")]
public async Task<SignIn> AuthenticateAccount([FromBody] SignIn authParam)
{

Sending this data to the API, normally it just sends raw, but I wrote a special service to handle Google SignIn and Googles gapi and gapi.auth2. I can't see how this special API" would encode the JSON.
{\"Id\":\"114251204162343478403\",\"FirstName\":\"John\",\"LastName\":\"Smith\",\"AccountName\":\"jsmith@hackme.com\",\"Password\":\"2H3HY4ZwE8Sb5Ajz\",\"Token\":\"eyJhbGciOiJIUsdadasdasd1lIjoiSmltIiwiZW1haWwiOiJqa2lya2VyeEBnbWFpbC5jb20iLCJuYmYiOjE1OTM0NjkwMDYsImV4cCI6MTU5MzY0MTgwNiwiaWF0IjoxNTkzNDY5MDA2LCJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo1MDAxLyIsImF1ZCI6asdsadasdasdasdwMS9hcGkifQ.WdpYg8qDIUtIT4uobyAWVQ01k9iNYJ6wPpa6FIXm3Yg\",\"Role\":\"Customer\",\"ExpiresAt\":\"2020-06-29T23:26:03.812Z\",\"IdpId\":\"gapi\",\"RememberMe\":true,\"Avatar\":{\"Url\":\"https://lh3.googleusercontent.com/a-/AOasdasdasdGJB_aUO-asdasdasdg-ob=s96-c\"}}

Don't get excited about the data, it's fake.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
Richard Deeming30-Jun-20 0:42
mveRichard Deeming30-Jun-20 0:42 
GeneralRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx30-Jun-20 7:06
professionaljkirkerx30-Jun-20 7:06 
Questionerror server Pin
Member 1265427722-Jun-20 3:37
Member 1265427722-Jun-20 3:37 
AnswerRe: error server Pin
ZurdoDev22-Jun-20 3:44
professionalZurdoDev22-Jun-20 3:44 
AnswerRe: error server Pin
Richard Deeming22-Jun-20 6:19
mveRichard Deeming22-Jun-20 6:19 
GeneralRe: error server Pin
Member 1265427723-Jun-20 0:37
Member 1265427723-Jun-20 0:37 
AnswerRe: error server Pin
Member 1265427723-Jun-20 0:41
Member 1265427723-Jun-20 0:41 
AnswerRe: error server Pin
OriginalGriff23-Jun-20 0:51
mveOriginalGriff23-Jun-20 0:51 
GeneralRe: error server Pin
Member 1265427723-Jun-20 2:34
Member 1265427723-Jun-20 2:34 
AnswerRe: error server Pin
OriginalGriff23-Jun-20 0:43
mveOriginalGriff23-Jun-20 0:43 
QuestionAnother NetCore question Pin
pkfox31-May-20 5:58
professionalpkfox31-May-20 5:58 
AnswerRe: Another NetCore question Pin
Mycroft Holmes31-May-20 13:22
professionalMycroft Holmes31-May-20 13:22 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 2:58
professionalpkfox1-Jun-20 2:58 
GeneralRe: Another NetCore question Pin
Mycroft Holmes1-Jun-20 13:44
professionalMycroft Holmes1-Jun-20 13:44 
AnswerRe: Another NetCore question Pin
Richard Deeming1-Jun-20 4:31
mveRichard Deeming1-Jun-20 4:31 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 5:08
professionalpkfox1-Jun-20 5:08 
AnswerRe: Another NetCore question Pin
jkirkerx1-Jun-20 14:47
professionaljkirkerx1-Jun-20 14:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.