Encountering difficulties when trying to pass my header parameter in Angular. The error I'm receiving from my API states "Session Id is required" as shown below. Here is the endpoint:
[HttpDelete("")]
public IActionResult EndSession(
[Required(ErrorMessage = "Session Id is required.")]
[StringLength(maximumLength: 36, MinimumLength = 36, ErrorMessage = "Session Id should be 36 characters long.")]
[FromHeader] string sessionId)
This is how my service method looks like in the angular application:
public async EndSession(sessionId: string): Promise<boolean> {
const headers = new HttpHeaders()
.set(sessionId , 'string')
this.appSettings = (await this.configService.loadConfig().toPromise());
return this.http.delete<boolean>(this.appSettings.apiSetting.apiAddress + this.apiRoute, { headers })
.pipe(
retry(1),
catchError(this.handleError)
)
.toPromise()
In the component where I call this method, the sessionId is hardcoded like so:
export class AppBarHorizontalComponent implements OnInit {
sessionId = "4CB3C85B-2C11-48AE-8D51-1DC30242A743"
constructor(private oauthService: OAuthService, private userService: UserSessionService) { }
public logout(): void {
this.userService.EndSession(this.sessionId);
//this.oauthService.logOut(false);
I expect that the sessionId will be correctly passed as a header parameter, allowing the api method to execute normally.