Search code examples
angularasp.net-web-apipingfederatepingaccess

Angular Get http response header without any WebAPI call?


I have a login authorization module that is installed on my sql server.

The module is triggered from my web.config file in my wwwroot directory.

  <modules>
      <add name="PingAccessModule"/>
    </modules>

In normal use case

I connect to my website www.connecttosite.com -> module intercepts request and logs user in -> request is verified then sends additional http headers to my web api where I can read these additional headers and get the user information.

The problem is this requires me to create an additional asp.net web api project that exists in the same directory as my angular application.

I want to know is there a way using angular only that I can connect to the website -> angular makes a call somehow -> module intercepts call -> attaches extra information to response header and I can see this header in angular and not have to use web api at all?

Can I use angular to act as web api?

EDIT:

So the current answer works if I want to create my own headers but the login module attaches user info to the headers.

See the photo below:

enter image description here

  1. The authorization is the very first call in the stack (circled in green). This is the module intercepting the request to the website and logging the user in.

  2. The red arrow is the actual call to the angular website. Then you can see the normal angular modules (main.js, env.js, polyfills etc) loading after.

  3. When the initial call is made to the website, the headers that I need will be available even before angular loads all of the modules. How do I access them right when angular loads?


Solution

  • Try to use a mock api for your situation.

    This should allow you to use angular as an api and call it from your normal angular client.

    So you would serve it and call it like so

    this.http.get('http://localhost:3000/api/YourMethodToGetUserInformation');