Check permission on every page
<p>in my web site i need to check permission on every page,
i found my self repeating the same code every page.</p>

<p>this is one of my pages</p>

<pre><code>public partial class KitView : AmsBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        IddUser user = new IddUser();
        user = (IddUser)Session["user"];

        bool isAdmin = user.roles.Where(IddRole =&gt; IddRole.R_ID.Equals(3)).First().IsInRole;
        bool isIddTeam = user.roles.Where(IddRole =&gt; IddRole.R_ID.Equals(2)).First().IsInRole;
        bool isProductionTeam = user.roles.Where(IddRole =&gt; IddRole.R_ID.Equals(1)).First().IsInRole;

        if (isAdmin)
        {
            hypAddComponent.Visible = true;
            hypAddComponent.NavigateUrl = "AddComponent.aspx?CKID=" + Request.QueryString["CKID"];
        }



    }
}
</code></pre>

<p>how is the best practice to have the roles: isAdmin,isIddTeam,isProductionTeam
in every page but not repeating the code below in every page code </p>

<pre><code>IddUser user = new IddUser();
        user = (IddUser)Session["user"];

        bool isAdmin = user.roles.Where(IddRole =&gt; IddRole.R_ID.Equals(3)).First().IsInRole;
        bool isIddTeam = user.roles.Where(IddRole =&gt; IddRole.R_ID.Equals(2)).First().IsInRole;
        bool isProductionTeam = user.roles.Where(IddRole =&gt; IddRole.R_ID.Equals(1)).First().IsInRole;
</code></pre>
