Forms authentication: disable redirect to the login page

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

    I'm not sure if this will work for everyone, but in IIS7 you can call Response.End() after you've set the status code and description. This way, that #&$^#@*! FormsAuthenticationModule won't do a redirect.

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

提交回复
热议问题