Forms authentication: disable redirect to the login page

后端 未结 12 2521
情歌与酒
情歌与酒 2020-12-02 09:29

I have an application that uses ASP.NET Forms Authentication. For the most part, it\'s working great, but I\'m trying to add support for a simple API via an .ashx file. I wa

12条回答
  •  独厮守ぢ
    2020-12-02 10:08

    what you've found out is correct about the forms auth intercepting the 401 and doing a redirect but we also can do that to reverse that.

    Basically what you need is an http module to intercept the 302 redirect to the login page and reverse it to a 401.

    Steps on doing that is explained in here

    The given link is about a WCF service but it is the same in all the forms auth scenarios.

    As explained in the above link you need to clear the http headers as well but remember to put the cookie header back to the response if the original response (i.e. before intercepting) contained any cookies.

提交回复
热议问题