0

I have an ASP.NET application with Forms Authentication, and is now implementing ApiControllers.

On my login page, I forward the user to the call he wanted after I signed him.

FormsAuthentication.RedirectFromLoginPage

And it works fine, IF it is a "GET" method, but if it is a "POST" method, then I get this error.

"The requested resource does not support http method 'GET'."

All methods work fine, BUT the first call must just be a "GET" method.

Is it not possible to "Redirect From Login Page" to a "POST" method?

2 Answers2

0

You can't issue a redirect to a POST, no. A redirect is always a GET. This is because a redirect is nothing more than the server telling the browser what address to go to.

Essentially you have two options:

  1. Support a GET method in your target action; or
  2. Display a page with a form which uses JavaScript to auto-submit a POST to the target action.

The first option seems much more reasonable and less prone to browser error.

David
  • 208,112
  • 36
  • 198
  • 279
  • Thanks for the answer. 1. I supports both GET and POST methods, but if I redirect to the GET method, I cannot get the posted JSON object. 2. The call is from an iPad App, so there is no page or JavaScript. So maybe the only solution is, that the user MUST have a session on the server before the first POST call..... – Peter Steiness Nov 11 '15 at 15:02
0

I found a solution.

I added this to my web.config file

  <location path="api">
    <system.web>
      <authorization>
        <allow users="*"></allow>
      </authorization>
    </system.web>
  </location>

Although I do not have any folder named "api", but all my API calls have the following syntax subdomain.domain.com/api/somename/...

It works…