Click here to Skip to main content
14,605,622 members
   

ASP.NET

 
GeneralRe: Generating unique user ID Pin
jkirkerx13-Jul-20 11:25
professionaljkirkerx13-Jul-20 11:25 
GeneralRe: Generating unique user ID Pin
DerekT-P17-Jul-20 10:44
professionalDerekT-P17-Jul-20 10:44 
Questionpls help Pin
Member 148797912-Jul-20 21:44
MemberMember 148797912-Jul-20 21:44 
SuggestionRe: pls help Pin
Richard MacCutchan2-Jul-20 21:48
mveRichard MacCutchan2-Jul-20 21:48 
GeneralRe: pls help Pin
ZurdoDev6-Jul-20 8:10
mveZurdoDev6-Jul-20 8:10 
AnswerRe: pls help Pin
David Mujica6-Jul-20 7:27
MemberDavid Mujica6-Jul-20 7:27 
JokeRe: pls help Pin
DerekT-P7-Jul-20 2:18
professionalDerekT-P7-Jul-20 2:18 
QuestionAngular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx29-Jun-20 12:48
professionaljkirkerx29-Jun-20 12: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 Deeming29-Jun-20 23:42
mveRichard Deeming29-Jun-20 23:42 
GeneralRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx30-Jun-20 6:06
professionaljkirkerx30-Jun-20 6:06 
Questionerror server Pin
Member 1265427722-Jun-20 2:37
MemberMember 1265427722-Jun-20 2:37 
AnswerRe: error server Pin
ZurdoDev22-Jun-20 2:44
mveZurdoDev22-Jun-20 2:44 
AnswerRe: error server Pin
Richard Deeming22-Jun-20 5:19
mveRichard Deeming22-Jun-20 5:19 
GeneralRe: error server Pin
Member 1265427722-Jun-20 23:37
MemberMember 1265427722-Jun-20 23:37 
AnswerRe: error server Pin
Member 1265427722-Jun-20 23:41
MemberMember 1265427722-Jun-20 23:41 
AnswerRe: error server Pin
OriginalGriff22-Jun-20 23:51
mveOriginalGriff22-Jun-20 23:51 
GeneralRe: error server Pin
Member 1265427723-Jun-20 1:34
MemberMember 1265427723-Jun-20 1:34 
AnswerRe: error server Pin
OriginalGriff22-Jun-20 23:43
mveOriginalGriff22-Jun-20 23:43 
QuestionAnother NetCore question Pin
pkfox31-May-20 4:58
professionalpkfox31-May-20 4:58 
AnswerRe: Another NetCore question Pin
Mycroft Holmes31-May-20 12:22
professionalMycroft Holmes31-May-20 12:22 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 1:58
professionalpkfox1-Jun-20 1:58 
GeneralRe: Another NetCore question Pin
Mycroft Holmes1-Jun-20 12:44
professionalMycroft Holmes1-Jun-20 12:44 
AnswerRe: Another NetCore question Pin
Richard Deeming1-Jun-20 3:31
mveRichard Deeming1-Jun-20 3:31 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 4:08
professionalpkfox1-Jun-20 4:08 
AnswerRe: Another NetCore question Pin
jkirkerx1-Jun-20 13:47
professionaljkirkerx1-Jun-20 13: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.