如何根据登录显示母版页内容 [英] how to show master page content according to login

查看:61
本文介绍了如何根据登录显示母版页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道根据登录热门对主页进行控制





例如我有一个母版页Access .Master有四个图像控制所以我想根据用户的登录情况根据角色显示四个中的两个。

I want to know that hot to render control on master page according to login


For example I have a master page Access.Master which has four image control so I want to show two out of four according to login of user means according to role.

推荐答案

是的,你可以做到。在您的子页面中添加此代码

Yes you can do it. In your child page add this code
Image ImageDashBoardIcon = (Image)this.Master.FindControl("Your Image ID");



根据您的角色执行所需的过程。


Do the required process according to your role.


您可以将visible属性设置为false,如下所示:



You can set the visible property to false, like so:

<asp:Image ID="imageName" runat="server" Visible="false" ImageUrl="yourURL"/>





然后在你的MasterPage.cs中设置如果在角色中可见:





Then in your MasterPage.cs set visible if in role:

if (HttpContext.Current.User.IsInRole("Admin"))
{
    imageName.Visible = true;
}
else
{
    imageName.Visible = false;
}





这对我来说是最简单的方法。



This is the easiest approach to me.


这篇关于如何根据登录显示母版页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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