登录后如何让管理员和其他用户查看不同的界面 [英] how to make admin and different user after logging in to see different interfaces
本文介绍了登录后如何让管理员和其他用户查看不同的界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
登录后看到不同的界面如何使管理员和不同的用户
how to make admin and different user after logging in to see different interfaces
推荐答案
u可以使用主题切换器!
将这两个代码片段放在两个类中,您可以将dropdownlist类拖到您的母版页上,它的工作效果很好!:)
要在您的网站上使用与此主题不同的主题,您应该有一个app_themes文件夹,并在其中设置主题!
代码:
这是您的HttpModule
:
u can use a theme switcher!
put this two code snip in two class,you can drag the dropdownlist class to your master page, its working just good!:)
for having different themes on your site that work with this you should have an app_themes folder, and set themes in there!
codes:
here is yourHttpModule
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.IO;
namespace ThemeSwitcher_CS
{
public class ThemeSwitcherModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(this.PreRequestHandlerExecute);
}
protected void PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpContext current = HttpContext.Current;
if (current.Handler is Page)
{
Page handler = (Page)current.Handler;
if (handler != null)
{
//These 8 lines below handle master pages. Courtesy of Craig G Fraser
string sUniqueID = "lbThemeSwitcher";
foreach (string str in current.Request.Form.AllKeys)
{
if (str.Contains("lbThemeSwitcher"))
{
sUniqueID = str;
break;
}
}
object theme = current.Request.Form[sUniqueID];
if (theme != null)
{
// this is postback from the page with the theme switcher list
// handle the user selection in the theme list
if (theme.ToString() == "0")
{
// user chose "none"
handler.Theme = "";
// delete the cookie
current.Response.Cookies[this.CookieName()].Expires = DateTime.Today.AddDays(-1.0);
}
else
{
if (this.ThemeExists(theme.ToString()))
{
handler.Theme = theme.ToString();
}
//set a cookie for persistence
current.Response.Cookies[this.CookieName()].Value = theme.ToString();
current.Response.Cookies[this.CookieName()].Expires = DateTime.Today.AddDays(90.0);
}
}
else
{
//for other pages with no theme switcher on them
HttpCookie cookie = current.Request.Cookies[this.CookieName()];
if ((cookie != null) && (cookie.Value != ""))
{
// if there's a cookie, get the theme from the cookie
if (this.ThemeExists(cookie.Value))
{
handler.Theme = cookie.Value;
}
}
else
{
// if there's no cookie, select the default theme (if it exists)
// the developer should provide a theme with the name "Default"
// if this behavior is wanted
if (this.ThemeExists("Default"))
{
handler.Theme = "Default";
}
string DefaultThemeName = ConfigurationManager.AppSettings["DefaultThemeName"];
if (this.ThemeExists(DefaultThemeName))
{
handler.Theme = DefaultThemeName;
}
}
}
}
}
}
private string CookieName()
{
string applicationPath = HttpContext.Current.Request.ApplicationPath;
return (applicationPath.Substring(1, applicationPath.Length - 1) + "_tsTheme");
}
private bool ThemeExists(string theme)
{
return Directory.Exists(HttpContext.Current.Server.MapPath("~/App_Themes/" + theme));
}
#endregion
}
}
这是您的dropdownlist控件类;
and here is your dropdownlist control class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace ThemeSwitcher_CS
{
public class ThemeSwitcher : DropDownList
{
// Methods
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.ID = "lbThemeSwitcher";
if (!this.Page.IsPostBack)
{
this.AutoPostBack = true;
if (this.AllowNoTheme)
{
this.Items.Add(new ListItem(this.NoThemeText, "0"));
}
if (Directory.Exists(this.Page.MapPath("~/App_Themes")))
{
foreach (string str in Directory.GetDirectories(this.Page.MapPath("~/App_Themes")))
{
DirectoryInfo info = new DirectoryInfo(str);
this.Items.Add(info.Name);
}
}
}
this.SelectedIndex = -1;
if ((this.Page.Theme == null) || (this.Page.Theme == ""))
{
this.SelectedIndex = 0;
}
else
{
ListItem item = this.Items.FindByValue(this.Page.Theme);
if (item != null)
{
item.Selected = true;
}
}
}
// Properties
[Description("Allow the user to choose no theme at all."), DefaultValue("False")]
public bool AllowNoTheme
{
get
{
object objectValue = RuntimeHelpers.GetObjectValue(this.ViewState["AllowNoTheme"]);
return ((objectValue != null) && (bool)objectValue);
}
set
{
this.ViewState["AllowNoTheme"] = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string DataMember
{
get
{
return base.DataMember;
}
set
{
base.DataMember = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string DataSourceID
{
get
{
return base.DataSourceID;
}
set
{
base.DataSourceID = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
public string DataTextField
{
get
{
return base.DataTextField;
}
set
{
base.DataTextField = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string DataTextFormatString
{
get
{
return base.DataTextFormatString;
}
set
{
base.DataTextFormatString = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string DataValueField
{
get
{
return base.DataValueField;
}
set
{
base.DataValueField = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ListItemCollection Items
{
get
{
return base.Items;
}
}
[DefaultValue("none"), Description("Show this text as the first option when AllowNoTheme is true")]
public string NoThemeText
{
get
{
object objectValue = RuntimeHelpers.GetObjectValue(this.ViewState["NoThemeText"]);
if (objectValue != null)
{
return objectValue.ToString();
}
return "none";
}
set
{
this.ViewState["NoThemeText"] = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
public ListSelectionMode SelectionMode
{
get
{
return ListSelectionMode.Single;
}
}
}
}
这篇关于登录后如何让管理员和其他用户查看不同的界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文