设置属性值从内容页母版页 [英] Set Property Value on Master Page from Content Page

查看:152
本文介绍了设置属性值从内容页母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要数据的每个页面加载时间传递给一个变量在我的母版页。

I need to pass data to a variable in my master page each time a page is loaded.

我有一个字符串[]我确定需要什么样的角色来访问该页面的每个内容页面上设置RequiredRoles的。

I have a string[] of RequiredRoles that I set on each content page defining what roles are required to access that page.

在我的母版页,我有借此阵列,并检查的方法,看看如果当前用户是在一个或多个这些角色的。

On my master page, I have a method that takes this array, and checks to see if the current user is in one or more of those roles.

我将如何去管理呢?我想基本上每个页面有一个String [] RequiredRoles定义,母版页会加载这个每次通话和检查,看看是否用户是这些角色。

How would I go about managing this? I basically want each page to have a String[] RequiredRoles defined, and the master page will load this on each call and check to see if the users are in those roles.

推荐答案

创建您的母版页的属性并从内容页访问:

Create a property in your master page and you access it from content page:

母版页:

public partial class BasePage : System.Web.UI.MasterPage
{
    private string[] _RequiredRoles = null;

    public string[] RequiredRoles
    {
        get { return _RequiredRoles; }
        set { _RequiredRoles = value; }
    }
}

内容页:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load()
    {
        Master.RequiredRoles = new string[] { /*set appropriate roles*/ };
    }
}

这篇关于设置属性值从内容页母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆