locked
How to throw the http403 forbidden error programmaticaly when I want to restrict the access to particular folder? RRS feed

  • Question

  • User230766423 posted

    Hello all,

    How to throw the http403 forbidden error programmaticaly when I want to restrict the access to particular folder?

    Swati

    Tuesday, April 10, 2007 4:41 AM

Answers

  • User-1087479560 posted
    Hi,

    Please try this:

    protected void Page_Load(object sender, EventArgs e)
    {
    Response.StatusCode = 403;
    Response.Flush();
    Response.End();
    }


    As a matter of fact, I think use a custom httpmodule to filter the request might be a better idea to fit your requirement.

    Hope it helps.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 11, 2007 2:01 AM
  • User-56913736 posted

    Hello,

    adding another method. It's not for folder as you asked, but you can use for any other place you want to throw http exception at..

    Throw New HttpException(403, "Nobody allowed this web site, except for me!, Warning....")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 12, 2007 7:25 AM

All replies

  • User587672878 posted

    My suggestion is to use the control authorization mechanism in the web.config to restrict folder access http://support.microsoft.com/kb/316871

    Then declare a customError handler for 403 error: http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx

    HTH

    Tuesday, April 10, 2007 2:33 PM
  • User-1087479560 posted
    Hi,

    Please try this:

    protected void Page_Load(object sender, EventArgs e)
    {
    Response.StatusCode = 403;
    Response.Flush();
    Response.End();
    }


    As a matter of fact, I think use a custom httpmodule to filter the request might be a better idea to fit your requirement.

    Hope it helps.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 11, 2007 2:01 AM
  • User-56913736 posted

    Hello,

    adding another method. It's not for folder as you asked, but you can use for any other place you want to throw http exception at..

    Throw New HttpException(403, "Nobody allowed this web site, except for me!, Warning....")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 12, 2007 7:25 AM