+ Reply to Thread
Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 47

Thread: Throw HTTP Status Code error

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

  2. #12
    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 don't think it does m...Thanks though..

    I think his is returning a 403 error and he wanted it to return a 404 instead. I presume he's using windows authentication on that particular folder and wanted to change the status code returned.

    In my head, this ought to be straightforward, but I can't seem to find how to do it..

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

    Looks like we'll have to wait for J

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

    Looks like it....Can't seem to find an answer on google either...I would have thought it would be fairly straightforward.

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

    I believe you'll have to handle this in an httpmodule. I have a link at home; I'll post it when I get the chance. I haven't had a chance to experiment with it, yet, either.

    The other option is to setup your system using a custom roles provider. Then you can simply deny these roles to the pages in web.config and then use the customErrors section to redirect to a specific page if a 403 is encountered.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  6. #16
    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 don't think specific roles provider would work because each user can have Create, Read, Update and Delete permissions on each section of a site. So, for example one user could have Read and Update permissions on the "Users" section and another could have Create and Read permissions, but not Update. So a roles list could be huge.

    I would have thought getting an ASP.NET page to return an HTTP Status Code shoudl be reasonably straightforward. Am I missing something here?

    The setup is in a web.sitemap file I have added custom parameters of Section and Permission. My master page retrieves the current node and then uses these parameters to check if the current user has the correct privileges.

    If they don't, I just want to return a 403 status code. Do you think it could be related to where I call this functionality? Currently it's in Page_Init of Master Page.

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

    Quote Originally Posted by richyrich View Post
    I don't think specific roles provider would work because each user can have Create, Read, Update and Delete permissions on each section of a site. So, for example one user could have Read and Update permissions on the "Users" section and another could have Create and Read permissions, but not Update. So a roles list could be huge.
    If the user has none of the roles, then they will not be granted authorization to that particular page. However, I'm not sure if it sends a 403 status code.

    Quote Originally Posted by richyrich View Post
    Am I missing something here?
    obviously

    Quote Originally Posted by richyrich View Post
    Do you think it could be related to where I call this functionality? Currently it's in Page_Init of Master Page.
    It has to happen before any page event. This is why an httpmodule would need to be used.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  8. #18
    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 jmurrayhead View Post
    It has to happen before any page event. This is why an httpmodule would need to be used.
    I think this may be the issue. In the code in my original post, I think the status code has already been returned so trying to set it to something else is having no effect..

    I think my Dynamic SiteMapNode code may work in this case....Think that uses something like an HttpModule...Will take a look and see if I can adjust it...

  9. #19
    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 have got this code, so far:-
    Code:
        public class PermissionModule : IHttpModule
        {
            public PermissionModule()
            {
            }
            public void Init(HttpApplication application)
            {
                application.BeginRequest +=
                    (new EventHandler(this.Application_BeginRequest));
                application.EndRequest +=
                    (new EventHandler(this.Application_EndRequest));
            }
    
            private User user { get; set; }
    
            public void Application_BeginRequest(Object source, EventArgs e)
            {
                // Create HttpApplication and HttpContext objects to access
                // request and response properties.
                HttpApplication application = (HttpApplication)source;
                //HttpContext context = application.Context;
                if (user == null)
                {
                    user = new User();
                    user = User.GetUser(Convert.ToInt32(application.Context.User.Identity.Name));
                }
    
                SiteMapNode node = SiteMap.CurrentNode;
                if (node != null)
                {
                    if (node["section"] != "0")
                    {
                        if (!user.admin && !user.CheckUserPermission(Convert.ToInt32(node["section"]), Convert.ToInt32(node["permission"])))
                            HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                    }
                }
    
            }
    
    But I am getting error "Object reference not set to an instance of an object" on line in red. Can I not retrieve the Current FormsAuthentication user in this context?

  10. #20
    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

    Try:
    Code:
    context HttpContext;
    context = HttpContext.Current;
    user = User.GetUser(Convert.ToInt32(context.User.Identity.Name));
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread
Page 2 of 5 FirstFirst 1 2 3 4 ... 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