+ Reply to Thread
Page 5 of 5 FirstFirst ... 3 4 5
Results 41 to 47 of 47

Thread: Throw HTTP Status Code error

  1. #41
    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

    OK...I've read numerous articles about this and still can't get it to work, so am giving up and just using a redirect if they don't authenticate.

  2. #42
    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

    Quote Originally Posted by richyrich View Post
    just using a redirect if they don't authenticate.
    I told you

  3. #43
    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

    Quote Originally Posted by micky View Post
    I told you
    yes, yes....Very clever...

    I still don't know why what I wanted to do wouldn't work. If I changed the status code value using the HTTP module when I retrieved it in the page it was showing as correct. But then it wasn't actually performing like that was the status code.

    I would have thought it would be something you would use when authenticating users.

    1) Authenticate a user
    2) Check if they have permission to view resource
    3) Return status code depending on whether they have permission or not.

    That's effectively how windows authentication works. Perhaps changing it in .NET is just too far down the request process to have any effect. Wonder why they've made it a get / set property then when changing it has no effect?

    Still I've only wasted a whole day trying to get it to work...

  4. #44
    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

    lol

    But i think it should work, something is being missed or done wrongly here

  5. #45
    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

    Quote Originally Posted by micky View Post
    lol

    But i think it should work, something is being missed or done wrongly here
    Yes...Something doesn't seem quite right...I think, although I can't really remember now, I got it to work with a 401 status, by putting it directly in the page (or master page) but it just kept redirecting to the login page, which isn't what I wanted.

    I couldn't find any similar example that used FormsAuthentication with status codes on google, so perhaps it just can't be done...:shrugs:

  6. #46
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    To get this to work, I did the following:

    web.config
    Code:
    <customErrors mode="On" defaultRedirect="~/Error.aspx">
        <error statusCode="403" redirect="~/Error.aspx?s=403" />
    </customErrors>
     
    <httpModules>
        <add name="AuthorizationModule" type="MyAuthorizationModule" />
    </httpModules>
    
    MyAuthorizationModule.vb
    Code:
    Public Class MyAuthorizationModule
        Implements IHttpModule
     
        Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
            AddHandler context.AuthorizeRequest, AddressOf Application_AuthorizeRequest
        End Sub
     
        Private Sub Application_AuthorizeRequest(ByVal sender As Object, ByVal e As EventArgs)
            ' Perform authorization business logic here
            ' If authorization business logic fails, call the following:
            ' HttpContext.Current.Response.StatusCode = CType(System.Net.HttpStatusCode.Forbidden, Integer)
            ' Throw New HttpException(403, "You are not authorized")
        End Sub
    End Class
    
    Hope this helps.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  7. #47
    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

    It did seem to kind of work in that it went to the page designated for a 403 error, but I just wanted the normal "You are not authorised page" and it was also not allowing users access to pages they should have access to.

    May as well just stick with what I got, I think...

+ Reply to Thread
Page 5 of 5 FirstFirst ... 3 4 5

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