mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 01:58:01 +08:00
增加身份认证支持缓存可分布式,增加异常处理及登录身份认证。
This commit is contained in:
12
Infrastructure/MVC/AuthenticationAttribute.cs
Normal file
12
Infrastructure/MVC/AuthenticationAttribute.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Infrastructure.MVC
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录验证
|
||||
/// </summary>
|
||||
public class AuthenticationAttribute: AuthorizeAttribute
|
||||
{
|
||||
}
|
||||
}
|
24
Infrastructure/MVC/JsonExceptionAttribute.cs
Normal file
24
Infrastructure/MVC/JsonExceptionAttribute.cs
Normal 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 }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
Infrastructure/MVC/LogExceptionAttribute.cs
Normal file
35
Infrastructure/MVC/LogExceptionAttribute.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
Infrastructure/MVC/NoFilterAttribute.cs
Normal file
10
Infrastructure/MVC/NoFilterAttribute.cs
Normal 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() { }
|
||||
}
|
||||
}
|
44
Infrastructure/MVC/UiResponse.cs
Normal file
44
Infrastructure/MVC/UiResponse.cs
Normal 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 = "";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user