我想基於用戶權限使用自定義安全框架禁用/啓用控件。我試圖在代碼隱藏文件中使用此代碼MVC3訪問控制
protected void OnLoadComplete(object sender, EventArgs e)
{
if ((ViewData[Constants.Permission]).Equals(Security.UserAccess.ReadOnlyAccess))
{
foreach (var control in this.Page.Controls )
{
control.IsReadOnly = true;
}
}
}
但是,控件的IsReadOnly屬性不可用。有沒有辦法可以解決這個問題或更好的方法來實現這一目標?
---更新---
Controller.cs
[Proxy.AimsAccessLevel]
public ActionResult Edit(int clientId)
{
ClientId = clientId;
//SetClientDetails();
var Selection = new SelectionArgs(clientId, null);
if (Selection.SelectionFlag == null || Selection.SelectionFlag == "N")
Selection.EffectiveDate = new DateTime(DateTime.Now.Year + 1, 1, 1);
return View(Selection);
}
proxy.cs
public class AccessLevel : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
Roles = Constants.AccessLevel.FullEdit + Constants.AccessLevel.ReadOnly.ToString() +
Constants.AccessLevel.RestrictedEdit;
return base.AuthorizeCore(httpContext);
}
}
MVC沒有一個代碼隱藏。你使用MVC還是WebForms? – 2012-03-26 15:01:38
即時通訊使用mvc我使用<%@ Page CodeBehind =「Edit.aspx.cs」Title =「」Language =「C#」MasterPageFile =「〜/ Views/Shared/Site.Master」Inherits =「Views.Selection.Edit」 %> 給了我沒有錯誤 – 2012-03-26 15:08:15