Base solution for your next web application
Open Closed

problem to use web.public project to serve AngularJS app #3793


User avatar
0
bcaa4567 created

Hi all,

I was trying to use the web.public project to host the Angular 4 SPA and ran into a few issues. The template I downloaded was ASPNet Core & Angular 4.4.0.

First problem was that I encountered the following error in the log file when I tried to login:

...
Service 'xxxx.Web.Authentication.JwtBearer.TokenAuthConfiguration' which was not registered.

Castle.MicroKernel.Handlers.HandlerException: Can't create component 'xxx.Web.Controllers.TokenAuthController' as it has dependencies to be satisfied.

...

So I added the following line in the startup.cs:

app.ApplicationServices.GetRequiredService<TokenAuthConfiguration>();

The error message changed to:

Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service xxx.Web.Authentication.JwtBearer.TokenAuthConfiguration was found

I am not sure how to proceed. What do I miss?

Thank you in advance!

derek

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

2 Answer(s)
  • User Avatar
    0
    bcaa4567 created

    I found out what the problem is. I need to copy the JwtBearer setting from host to public project. I ran into next problem.

    ...idateAntiforgeryTokenAuthorizationFilter - Antiforgery token validation failed. The required antiforgery header value "Public-X-XSRF-TOKEN" is not present.
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @BCAA4567,

    Do you use cshtml files or html files for your angularJS app ? If it is cshtml, then you need to add below code to your layout cshtml file.

    @{
        SetAntiForgeryCookie();
    }
    

    If you are using html, then you need to include this header to your ajax requests. You can get anti forgery token value using below code.

    abp.security.antiForgery.getToken()
    

    Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)