时间:2016-02-15 22:30 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP.NET.4.5.1+MVC5.0设置系统角色与权限(一)】,下面是详细的讲解!
ASP.NET.4.5.1+MVC5.0设置系统角色与权限(一)
namespace HR.Helpers
{
public class ControllerBase : Controller
{
/// <summary>
/// 操作人,传IP....到后端记录
/// </summary>
public virtual Operater Operater
{
get
{
return null;
}
}
/// <summary>
/// 分页大小
/// </summary>
public virtual int PageSize
{
get
{
return 15;
}
}
protected ContentResult JsonP(string callback, object data)
{
var json=Newtonsoft.Json.JsonConvert.SerializeObject(data);
return this.Content(string.Format("{0}({1})", callback, json));
}
/// <summary>
/// 当弹出DIV弹窗时,需要刷新浏览器整个页面
/// </summary>
/// <returns></returns>
public ContentResult RefreshParent(string alert=null)
{
var script=string.Format("<script>{0}; parent.location.reload(1)</script>", string.IsNullOrEmpty(alert) ? string.Empty : "alert('" + alert + "')");
return this.Content(script);
}
public new ContentResult RefreshParentTab(string alert=null)
{
var script=string.Format("<script>{0}; if (window.opener !=null) {{ window.opener.location.reload(); window.opener=null;window.open('', '_self', ''); window.close()}} else {{parent.location.reload(1)}}</script>", string.IsNullOrEmpty(alert) ? string.Empty : "alert('" + alert + "')");
return this.Content(script);
}
/// <summary>
/// 用JS关闭弹窗
/// </summary>
/// <returns></returns>
public ContentResult CloseThickbox()
{
return this.Content("<script>top.tb_remove()</script>");
}
/// <summary>
/// 警告并且历史返回
/// </summary>
/// <param name="notice"></param>
/// <returns></returns>
public ContentResult Back(string notice)
{
var content=new StringBuilder("<script>");
if (!string.IsNullOrEmpty(notice))
content.AppendFormat("alert('{0}');", notice);
content.Append("history.go(-1)</script>");
return this.Content(content.ToString());
}
public ContentResult PageReturn(string msg, string url=null)
{
var content=new StringBuilder("<script type='text/javascript'>");
if (!string.IsNullOrEmpty(msg))
content.AppendFormat("alert('{0}');", msg);
if (string.IsNullOrWhiteSpace(url))
url=Request.Url.ToString();
content.Append("window.location.href='" + url + "'</script>");
return this.Content(content.ToString());
}
/// <summary>
/// 转向到一个提示页面,然后自动返回指定的页面
/// </summary>
/// <param name="notice"></param>
/// <param name="redirect"></param>
/// <returns></returns>
public ContentResult Stop(string notice, string redirect, bool isAlert=false)
{
var content="<meta http-equiv='refresh' content='1;url=" + redirect + "' /><body style='margin-top:0px;color:red;font-size:24px;'>" + notice + "</body>";
if (isAlert)
content=string.Format("<script>alert('{0}'); window.location.href='{1}'</script>", notice, redirect);
return this.Content(content);
}
/// <summary>
/// 在方法执行前更新操作人
/// </summary>
/// <param name="filterContext"></param>
public virtual void UpdateOperater(ActionExecutingContext filterContext)
{
if (this.Operater==null)
return;
WCFContext.Current.Operater=this.Operater;
}
public virtual void ClearOperater()
{
//TODO
}
/// <summary>
/// AOP拦截,在Action执行后
/// </summary>
/// <param name="filterContext">filter context</param>
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
if (!filterContext.RequestContext.HttpContext.Request.IsAjaxRequest() && !filterContext.IsChildAction)
RenderViewData();
this.ClearOperater();
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
this.UpdateOperater(filterContext);
base.OnActionExecuting(filterContext);
//在方法执行前,附加上PageSize值
filterContext.ActionParameters.Values.Where(v=> v is Request).ToList().ForEach(v=> ((Request)v).PageSize=this.PageSize);
}
/// <summary>
/// 产生一些视图数据
/// </summary>
protected virtual void RenderViewData()
{
}
/// <summary>
/// 当前Http上下文信息,用于写Log或其他作用
/// </summary>
public WebExceptionContext WebExceptionContext
{
get
{
var exceptionContext=new WebExceptionContext
{
IP=Fetch.UserIp,
CurrentUrl=Fetch.CurrentUrl,
RefUrl=(Request==null || Request.UrlReferrer==null) ? string.Empty : Request.UrlReferrer.AbsoluteUri,
IsAjaxRequest=(Request==null) ? false : Request.IsAjaxRequest(),
FormData=(Request==null) ? null : Request.Form,
QueryData=(Request==null) ? null : Request.QueryString,
RouteData=(Request==null || Request.RequestContext==null || Request.RequestContext.RouteData==null) ? null : Request.RequestContext.RouteData.Values
};
return exceptionContext;
}
}
/// <summary>
/// 发生异常写Log
/// </summary>
/// <param name="filterContext"></param>
protected override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
var e=filterContext.Exception;
LogException(e, this.WebExceptionContext);
}
protected virtual void LogException(Exception exception, WebExceptionContext exceptionContext=null)
{
//do nothing!
}
}
public class WebExceptionContext
{
public string IP { get; set; }
public string CurrentUrl { get; set; }
public string RefUrl { get; set; }
public bool IsAjaxRequest { get; set; }
public NameValueCollection FormData { get; set; }
public NameValueCollection QueryData { get; set; }
public RouteValueDictionary RouteData { get; set; }
}
}
关于ASP.NET.4.5.1+MVC5.0设置系统角色与权限(一)的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【asp】asp.net ubb使用代码-net-ubb使用
- 【默认图片】图片不存在使用默认图片代替的实例
- 【asp】asp.net 页面转向 Response.Redirect Ser
- 【页面打印】关于ASP.NET页面打印技术的常用方法
- 【MVC5】MVC 5 第一章 创建MVC 5 web应用程序-net
- 【MVC】一个简单MVC5 + EF6示例分享-EF6实例-MVC5
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
