本文整理汇总了C#中System.Web.Mvc.ActionDescriptor.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# ActionDescriptor.IsDefined方法的具体用法?C# ActionDescriptor.IsDefined怎么用?C# ActionDescriptor.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.ActionDescriptor
的用法示例。
在下文中一共展示了ActionDescriptor.IsDefined方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Redirect
/// <summary>
/// 重定向方法 有两种情况:如果是Ajax请求,则返回 Json字符串;如果是普通请求,则 返回重定向命令
/// </summary>
/// <param name="IsNoLogin">判断是未登录还是没有权限</param>
/// <param name="url"></param>
/// <param name="action"></param>
/// <returns></returns>
public ActionResult Redirect(bool IsLogin, ActionDescriptor action)
{
//如果Ajax请求没有权限,就返回 Json消息
if (action.IsDefined(typeof(AjaxRequestAttribute), false)
|| action.ControllerDescriptor.IsDefined(typeof(AjaxRequestAttribute), false))
{
if (IsLogin)
{
return RedirectAjax("nologin", null, null, "/Login/Login/Index");
}
else
{
Uri MyUrl = Request.UrlReferrer;
string url = MyUrl.ToString();
return RedirectAjax("nopermission", "您没有权限访问此页面", null, url);
}
}
else//如果 超链接或表单 没有权限访问,js代码
{
if (IsLogin)
{
ContentResult result = new ContentResult();
//跳回登陆页面
result.Content = "<script type='text/javascript'>alert('您还没有登陆呦!');parent.location='" +"/Login/Login/Index"+ "'</script>"; ;
return result;
}
else
{
//返回上一级URL
Uri MyUrl = Request.UrlReferrer;
string url = MyUrl.ToString();
ContentResult result = new ContentResult();
result.Content = "<script type='text/javascript'>alert('您没有权限访问此页面!');window.location='" + url + "'</script>";
return result;
}
}
}
示例2: Redirect
/// <summary>
/// 重定向方法 有两种情况:如果是Ajax请求,则返回 Json字符串;如果是普通请求,则 返回重定向命令
/// </summary>
/// <returns></returns>
public ActionResult Redirect(string url, ActionDescriptor action)
{
//如果Ajax请求没有权限,就返回 Json消息
if (action.IsDefined(typeof(AjaxRequestAttribute), false)
|| action.ControllerDescriptor.IsDefined(typeof(AjaxRequestAttribute), false))
{
return RedirectAjax("nologin", "您没有登陆或没有权限访问此页面~~", null, url);
}
else//如果 超链接或表单 没有权限访问,则返回 302重定向命令
{
return new RedirectResult(url);
}
}
示例3: HasAllowAnonymousAttribute
private bool HasAllowAnonymousAttribute(ActionDescriptor actionDescriptor)
{
var allowAnonymousType = typeof(AllowAnonymousAttribute);
return (actionDescriptor.IsDefined(allowAnonymousType, true) ||
actionDescriptor.ControllerDescriptor.IsDefined(allowAnonymousType, true));
}