📄 defaultcs.aspx.cs
字号:
using System;
using System.Threading;
using System.Web.Security;
using System.Web.UI.WebControls;
namespace Telerik.EditorExamplesCSharp.Editor.Examples.Security
{
/// <summary>
/// Summary description for DefaultCS.
/// </summary>
public class DefaultCS : Telerik.QuickStart.XhtmlPage
{
protected Telerik.WebControls.RadEditor editor1;
protected System.Web.UI.WebControls.LinkButton btnLogout;
protected Label infoLabel;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
Response.Redirect(this.TemplateSourceDirectory + "/LoginCS.aspx");
}
infoLabel.Text = "<span style='color: red'>You are logged in as: <b>" + Thread.CurrentPrincipal.Identity.Name + "</b></span>";
if (Thread.CurrentPrincipal.Identity.Name == "superadmin")
{
editor1.HasPermission = true;
editor1.Editable = true;
editor1.Html = "This text will be seen by superadmin users.";
// IMPORTANT !!!! - API for FAST CUSTOMIZATION OF USER DIRECTORIES
string[] dirs = new string[] { "~/Editor/Img" };
editor1.SetPaths(dirs,
Telerik.WebControls.EditorFileTypes.All
//Telerik.WebControls.EditorFileTypes.Documents |
//Telerik.WebControls.EditorFileTypes.Images |
//Telerik.WebControls.EditorFileTypes.Flash |
//Telerik.WebControls.EditorFileTypes.Media
,
Telerik.WebControls.EditorFileOptions.All
//Telerik.WebControls.EditorFileOptions.Browse |
//Telerik.WebControls.EditorFileOptions.Upload |
//Telerik.WebControls.EditorFileOptions.Delete
);
}
else if (Thread.CurrentPrincipal.Identity.Name == "admin")
{
editor1.HasPermission = true;
editor1.Editable = true;
// Other editor properties can be changed here - security policies can be very fine-grained, e.g.
editor1.Html = "This text will be seen by admin users.";
// IMPORTANT !!!! - API for FAST CUSTOMIZATION OF USER DIRECTORIES
string[] dirs = new string[] { "~/Editor/Img" };
editor1.SetPaths(dirs,
Telerik.WebControls.EditorFileTypes.All
//Telerik.WebControls.EditorFileTypes.Documents |
//Telerik.WebControls.EditorFileTypes.Images |
//Telerik.WebControls.EditorFileTypes.Flash |
//Telerik.WebControls.EditorFileTypes.Media
,
Telerik.WebControls.EditorFileOptions.All
//Telerik.WebControls.EditorFileOptions.Browse |
//Telerik.WebControls.EditorFileOptions.Upload |
//Telerik.WebControls.EditorFileOptions.Delete
);
}
else
{
infoLabel.Text = "<span style='color: red'>Your session has probably expired</span>";
editor1.Html = "You must log-in as admin or superadmin to edit this content.";
editor1.HasPermission = false;
editor1.Editable = true;
}
}
protected void btnLogout_Click(object sender, System.EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect(this.TemplateSourceDirectory + "/LoginCS.aspx");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
btnLogout.Click += new EventHandler(btnLogout_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -