Bonjour à tous,

J'utilise un petit script qui permet de vérifier qu'un utilisateur a le droit d'accéder à une page (selon les rôles définis dans le sitemap). Ca marche presque parfaitement sauf un petit détail.

Dans le cas ou je suis sur la page de login et qu'il y a un paramètre ReturnUrl, je ne suis pas redirigé vers la page pointée par le returnURL mais vers ma page Default.aspx.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
 
 
//Script adapted from: http://www.codeproject.com/KB/web-security/aspnet2security.aspx
namespace E2S.Website.Class
{
 
    /// <summary>Security Http Module</summary>
    public class SecurityHttpModule : IHttpModule
    {
 
        public SecurityHttpModule() { }
        /// <summary>Initializes a module and prepares
        /// it to handle requests.</summary>
        /// <param name="context" 
        /// >An <see cref="T:System.Web.HttpApplication" />
        /// that provides access to the methods, properties,
        /// and events common to all application objects within
        /// an ASP.NET application </param>
        public void Init(System.Web.HttpApplication context)
        {
            context.AuthenticateRequest += new
                    EventHandler(this.AuthenticateRequest);
        }
 
        /// <summary>Occurs when a security module
        /// has established the identity of the user.</summary>
        private void AuthenticateRequest(Object sender, EventArgs e)
        {
            HttpApplication Application = (HttpApplication)sender;
            HttpRequest Request = Application.Context.Request;
            HttpResponse Response = Application.Context.Response;
            bool allow = false; // Default is not allow
 
 
            if (Request.Url.AbsolutePath.ToLower() != FormsAuthentication.LoginUrl.ToLower()
                && Application.Context.User != null
                && SiteMap.CurrentNode != null)
            {
                // Check if user is in roles
                if (SiteMap.CurrentNode.Roles.Count == 0)
                {
                    allow = true; // No Roles found, so we allow.
                }
                else
                {
                    // Loop through each role and check to see if user is in it.
                    foreach (string role in SiteMap.CurrentNode.Roles)
                    {
                        if (Roles.IsUserInRole(role)) { allow = true; break; }
                    }
                }
 
                // Do we deny?
                if (allow == false)
                    Response.Redirect("~/Website/Exception/notAllow.aspx");
            }
        }
 
        /// <summary>Disposes of the resources (other than memory)
        /// used by the module that implements
        /// <see cref="T:System.Web.IHttpModule" />.</summary>
 
        public void Dispose() { }
    }
}
Quelqu'un voit il pourquoi?