增加身份认证支持缓存可分布式,增加异常处理及登录身份认证。

This commit is contained in:
kuaigoumanzhu
2016-08-27 01:27:26 +08:00
parent 981b595bcc
commit 6a507d0fa7
14 changed files with 459 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
using System.Web;
using System.Web.Mvc;
namespace Infrastructure.MVC
{
/// <summary>
/// 登录验证
/// </summary>
public class AuthenticationAttribute: AuthorizeAttribute
{
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Web.Mvc;
namespace Infrastructure.MVC
{
/// <summary>
/// 加入action级ajax请求发生500内部错误时返回给浏览器json提示
/// </summary>
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class JsonExceptionAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if (!filterContext.ExceptionHandled)
{
//返回异常json
filterContext.Result = new JsonResult
{
Data = new UiResponse { statusCode = "300", message = filterContext.Exception.Message }
};
}
}
}
}

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace Infrastructure.MVC
{
/// <summary>
/// 加入全局异常处理500内部错误
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public class LogExceptionAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if (!filterContext.ExceptionHandled)
{
string controllerName = filterContext.RouteData.Values["controller"].ToString();
string actionName = filterContext.RouteData.Values["action"].ToString();
string msgTemp = WebUtility.GetIP() + "在执行controller" + controllerName + "的" + actionName + "时产生异常:" + filterContext.Exception.Message;
//hpf此处写入异常日志
LogHelper.Fatal(msgTemp);
}
if (filterContext.Result is JsonResult)
{
filterContext.ExceptionHandled = true;//异常已处理
}
else
{
//通过base返回系统默认异常处理上向错误页面跳转
base.OnException(filterContext);
}
}
}
}

View File

@@ -0,0 +1,10 @@
using System;
namespace Infrastructure.MVC
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class NoFilterAttribute : Attribute
{
public NoFilterAttribute() { }
}
}

View File

@@ -0,0 +1,44 @@

namespace Infrastructure.MVC
{
/// <summary>
/// 前端框架ajax错误返回
/// </summary>
public class UiResponse
{
public string statusCode
{
get; set;
}
public string message
{
get; set;
}
public string tabid
{
get; set;
}
public bool closeCurrent
{
get; set;
}
public string forward { get; set; }
public string forwardConfirm { get; set; }
public UiResponse()
{
statusCode = "200";
message = "操作成功";
tabid = "";
closeCurrent = false;
forward = "";
forwardConfirm = "";
}
}
}