+ Reply to Thread
Page 1 of 5 1 2 3 ... LastLast
Results 1 to 10 of 47

Thread: Throw HTTP Status Code error

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Throw HTTP Status Code error

    I'm building a site that uses FormsAuthentication, so users have to login. When they login, they have various permissions for different areas of the site.

    If they try to access a page that they don't have permission for I want to throw a 403 status code error so they see the forbidden page.

    Any ideas how to go about this?

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I have tried just setting the StatusCode of the Current HttpContext
    Code:
    HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Forbidden;
    
    but that doesn't seem to do anything. It just processes the page as normal.

    I put it in the Page_Load event of my Master Page. Should I try it before it reaches this event?

  3. #3
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    I check value of "HttpContext.Current.User.Identity.Name" in Master page and accordingly not show its link in left menu.

    But i dont know whats your set up.

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Yes, I do that already m.

    What I want to do is if a user types the page into the address bar then it shows the standard 403 error page ie You do not have permission to view this resource etc.

    So, basically I want to return a status code of 403 to the browser and then it shows the standard 403 error page, I think...

    If I throw an HttpException it shows the .NET exception page, which I don't want. I want to 403 error page to show

  5. #5
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    So just check if they have permission or not, if not, then redirect to such page (make such page).

    Thats how i would do it......... but generally its not the right way

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Yes, I could do that.

    I just thought I would try and use the pages already there rather than building more pages. IE if they don't have permission, just return a 403 status.

    Then at least I could add custom error pages at a later date if I wanted.

  7. #7
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    How do you call such existing pages??

    Or do you have to do something in IIS?

    Or you are asking this only??

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    All I really want to happen is that if a user browses to a page they don't have access to, the asp.net page sends back a 403 status code and, currently, the user would see the default 403 (You do not have permission to view this resource) page.

  9. #9
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    How do you determine that user has permission or not??

  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    The user logs in using FormsAuthentication.

    Each page is allocated a Section and Permission variable. I then check this against a UserRoles db table to see if they have permission or not.

    If they don't then I want to return a 403 status code.

+ Reply to Thread
Page 1 of 5 1 2 3 ... LastLast

Similar Threads

  1. http://conception-2-school.com/forums/
    By jmurrayhead in forum Website Reviews
    Replies: 15
    Last Post: April 22nd, 2009, 01:11 PM
  2. Need PHP/SQL code help...to fix written code
    By honeybeeaz in forum PHP Development
    Replies: 10
    Last Post: November 11th, 2008, 03:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO