dnn-sxc-angular HttpInterceptor
One of the core challenges when using any JavaScript in Dnn is ensuring that WebAPI calls have all the important http headers to make it work. This is what the HttpInterceptor does. It ensures that:
- Security headers like the
RequestVerificationToken
are included - Context headers like
ModuleId
are correct - Shorthand api urls like
app/data/BlogPost
are mapped to the correct endpoints
How it works
For this to work, the page must have this data available before Angular loads. Thanks to 2sxc (the non-angular parts) this is automatically provided ahead of time. Here's the initialization process behind the scenes:
- 2sxc adds important headers to the page on the server for 2sxc and dnn-sxc-angular to work (this happens automatically)
- When the root module is built (usually called
AppModule
) it must includeDnnSxcRootModule
to register the Http-Interceptor - When Angular bootstraps the base class
DnnAppComponent
gets everything from the page when it's constructed. Without this the Http-Interceptor wouldn't have the configuration necessary.
After this has happened, all calls using the Angular HttpClient will automatically behave as expected.