Redirect from Attribute

Posted by pistacchio on Stack Overflow See other posts from Stack Overflow or by pistacchio
Published on 2011-01-19T17:57:25Z Indexed on 2011/03/20 19:21 UTC
Read the original article Hit count: 227

Filed under:
|

How can I create an attribute for an ASP.NET page that redirects to another page?

[MyAttribute()]
public partial class Default : System.Web.UI.Page
{

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

    }
}

[AttributeUsage(AttributeTargets.All)]
public class MyAttribute: Attribute
{
    public MyAttribute()
    {
        if (// something)
        { 
            // I need to redirect to some page here 
        }

    }
}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about attributes