如何根据登录显示母版页内容

如何根据登录显示母版页内容

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

问题描述

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





例如我有一个母版页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.

推荐答案

Image ImageDashBoardIcon = (Image)this.Master.FindControl("Your Image ID");



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


Do the required process according to your role.


<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.


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

08-14 16:19