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

Detlef D. Doerscheln picture Detlef D. Doerscheln · Oct 20, 2008 · Viewed 40.4k times · Source

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 it would show the IIS standard page.

Answer

Mark Cidade picture Mark Cidade · Oct 20, 2008
Response.StatusCode = 401;
Response.End();