Forms authentication: disable redirect to the login page

后端 未结 12 2522
情歌与酒
情歌与酒 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:24

    ASP.NET 4.5 added the Boolean HttpResponse.SuppressFormsAuthenticationRedirect property.

    public void ProcessRequest(HttpContext context)
    {
        Response.StatusCode = 401;
        Response.StatusDescription = "Authentication required";
        Response.SuppressFormsAuthenticationRedirect = true;
    }
    

提交回复
热议问题