How to generate an 401 error programmatically in an ASP.NET page

后端 未结 5 1387
无人及你
无人及你 2020-12-08 02:29

As you can see this is a question from a non web developer. I would like to have an ASPX page which, under certain circumstances, can generate a 401 error from code. Ideally

5条回答
  •  旧巷少年郎
    2020-12-08 02:55

    One additional comment.

    If a portion of the page has already been written to the output buffer then it is important that you clear any buffered content or the page may not appear correctly.

    This is quite likely in a templated environment. e.g. Master pages...

    Response.ClearContent();
    Response.StatusCode = 401;
    Response.End();
    

提交回复
热议问题