Tal Abziz
Tal Abziz

Reputation: 109

how to serve asp.net core Angular SPA over HTTP POST

I am trying to develop an LTI tool using asp.net core and its Angular SPA template. A Learning Management System could use my tool (which is a web app) by embedding an i-frame of it inside their website, and they do so by using an HTTP POST request with additional form-data attached to it. If I would use an asp.net core MVC project, that POST request would reach that same action a GET request would reach and the desired view would render, but with the Angular project template I would arrive to an empty html page with this message

Cannot POST /

I could achieve a work around by adding an action with [Post("/")] attribute and redirect to the home page by using Redirect("/") but I was wondering if there's a better solution.

Upvotes: 0

Views: 740

Answers (1)

Tal Abziz
Tal Abziz

Reputation: 109

So I found a better way of getting the page and also preserving the form data. I just created a custom middleware and changed the POST request to a GET request. it preserves headers and allows setting cookies, unlike Redirect("/")

app.Use(async (context, next) => 
    {
        if (context.Request.IsAuthenticatedWithLti())
            context.Request.Method = HttpMethods.Get;
        await next.Invoke();
    });

Upvotes: 2

Related Questions