diff --git a/Api/Ewide.Core/Ewide.Core.Arguments/Ewide.Core.DTO.csproj b/Api/Ewide.Core/Ewide.Core.Arguments/Ewide.Core.DTO.csproj
index 1f26cf9..4c0acfd 100644
--- a/Api/Ewide.Core/Ewide.Core.Arguments/Ewide.Core.DTO.csproj
+++ b/Api/Ewide.Core/Ewide.Core.Arguments/Ewide.Core.DTO.csproj
@@ -43,6 +43,7 @@
+
diff --git a/Api/Ewide.Core/Ewide.Core.Arguments/LoginDTO.cs b/Api/Ewide.Core/Ewide.Core.Arguments/LoginDTO.cs
new file mode 100644
index 0000000..4beafa5
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.Arguments/LoginDTO.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ewide.Core.DTO
+{
+ public class LoginDTO
+ {
+ [DisplayName("登录帐号")]
+ [Required(AllowEmptyStrings = false, ErrorMessage = "登录帐号不可为空")]
+ public string Account { get; set; }
+
+ [DisplayName("登录密码")]
+ [Required(AllowEmptyStrings = false, ErrorMessage = "登录密码不可为空")]
+ public string Password { get; set; }
+ }
+}
diff --git a/Api/Ewide.Core/Ewide.Core.DTO/Ewide.Core.DTO.csproj b/Api/Ewide.Core/Ewide.Core.DTO/Ewide.Core.DTO.csproj
new file mode 100644
index 0000000..7d6d427
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.DTO/Ewide.Core.DTO.csproj
@@ -0,0 +1,49 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {590704FF-28C5-4536-B587-AC213858CC42}
+ Library
+ Properties
+ Ewide.Core.DTO
+ Ewide.Core.DTO
+ v4.5.2
+ 512
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Api/Ewide.Core/Ewide.Core.DTO/LoginDTO.cs b/Api/Ewide.Core/Ewide.Core.DTO/LoginDTO.cs
new file mode 100644
index 0000000..c5ee089
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.DTO/LoginDTO.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ewide.Core.DTO
+{
+ public class LoginDTO
+ {
+ [DisplayName("登录帐号")]
+ [Phone(ErrorMessage = "a a")]
+ [Required(AllowEmptyStrings = false, ErrorMessage = "登录帐号不可为空")]
+ public string Account { get; set; }
+
+ [DisplayName("登录密码")]
+ [Required(AllowEmptyStrings = false, ErrorMessage = "登录密码不可为空")]
+ public string Password { get; set; }
+ }
+}
diff --git a/Api/Ewide.Core/Ewide.Core.DTO/Properties/AssemblyInfo.cs b/Api/Ewide.Core/Ewide.Core.DTO/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..504cf32
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.DTO/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Ewide.Core.DTO")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Ewide.Core.DTO")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("590704ff-28c5-4536-b587-ac213858cc42")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Api/Ewide.Core/Ewide.Core.Service/Ewide.Core.Service.csproj b/Api/Ewide.Core/Ewide.Core.Service/Ewide.Core.Service.csproj
index 89b474d..874d932 100644
--- a/Api/Ewide.Core/Ewide.Core.Service/Ewide.Core.Service.csproj
+++ b/Api/Ewide.Core/Ewide.Core.Service/Ewide.Core.Service.csproj
@@ -45,10 +45,6 @@
-
- {9003b29c-ac1d-444e-8fe2-201f76d848a5}
- Ewide.Core.DTO
-
{c7e2ac14-ac20-4552-a5b8-08b650ac8416}
Ewide.Core.Common
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/Filters/HttpNotFoundControllerActionSelector.cs b/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/Filters/HttpNotFoundControllerActionSelector.cs
index 05f1fa2..f5521ef 100644
--- a/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/Filters/HttpNotFoundControllerActionSelector.cs
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/Filters/HttpNotFoundControllerActionSelector.cs
@@ -27,7 +27,7 @@ namespace Ewide.Core.WebApi
catch (HttpResponseException ex)
{
var code = ex.Response.StatusCode;
- var result = BaseDisplayJSON.Display(code, "请求方式错误");
+ var result = BaseDisplayJSON.Display(code, code == HttpStatusCode.NotFound ? "找不到接口,请确认接口地址是否正确" : "请求方式错误");
if (code == HttpStatusCode.NotFound || code == HttpStatusCode.MethodNotAllowed)
{
ex.Response.Content = new ObjectContent(result.GetType(), result, formatter);
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/WebApiConfig.cs b/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/WebApiConfig.cs
index 545e8f8..2ab242e 100644
--- a/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/WebApiConfig.cs
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/App_Start/WebApiConfig.cs
@@ -16,26 +16,21 @@ namespace Ewide.Core.WebApi
// Web API 路由
config.MapHttpAttributeRoutes();
- #region 处理接口报错
- // 404
- config.Services.Replace(typeof(IHttpControllerSelector), new HttpNotFoundDefaultHttpControllerSelector(config));
- // 500
- config.Services.Replace(typeof(IHttpActionInvoker), new HttpWebApiControllerActionInvoker(config));
- // 405
- config.Services.Replace(typeof(IHttpActionSelector), new HttpNotFoundControllerActionSelector(config));
- #endregion
-
- config.Routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new { id = RouteParameter.Optional }
- );
-
config.Routes.MapHttpRoute(
name: "DefaultAreaApi",
- routeTemplate: "api/{area}/{controller}/{action}/{id}",
+ routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
+
+ #region 处理接口报错
+ // 以下404处理不包括地址段错误的情况,如直接访问/aaa或/api/controller/action/id/aaa都会返回404错误页
+ // 404
+ config.Services.Replace(typeof(IHttpControllerSelector), new HttpNotFoundDefaultHttpControllerSelector(config));
+ // 404/405
+ config.Services.Replace(typeof(IHttpActionSelector), new HttpNotFoundControllerActionSelector(config));
+ // 500
+ config.Services.Replace(typeof(IHttpActionInvoker), new HttpWebApiControllerActionInvoker(config));
+ #endregion
}
}
}
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/BaseAreaRegistration.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/BaseAreaRegistration.cs
new file mode 100644
index 0000000..865c17e
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/BaseAreaRegistration.cs
@@ -0,0 +1,24 @@
+using System.Web.Mvc;
+
+namespace Ewide.Core.WebApi.Areas.Base
+{
+ public class BaseAreaRegistration : AreaRegistration
+ {
+ public override string AreaName
+ {
+ get
+ {
+ return "Base";
+ }
+ }
+
+ public override void RegisterArea(AreaRegistrationContext context)
+ {
+ context.MapRoute(
+ "Base_default",
+ "Base/{controller}/{action}/{id}",
+ new { action = "Index", id = UrlParameter.Optional }
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Controllers/BetestController.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Controllers/BetestController.cs
new file mode 100644
index 0000000..301526d
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Controllers/BetestController.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+
+namespace Ewide.Core.WebApi.Areas.Base.Controllers
+{
+ [ValidateArgumentsFilter]
+ public class BetestController : BaseController
+ {
+ ///
+ /// 获取所有接口及其注释
+ ///
+ ///
+ [Route("test22")]
+ [HttpPost]
+ public IHttpActionResult Test1()
+ {
+ var apis = Configuration.Services.GetApiExplorer().ApiDescriptions;
+
+ var result = apis
+ .Select(p => new
+ {
+ p.RelativePath,
+ p.Documentation
+ });
+ return DisplayJSON(result);
+ }
+
+ [HttpPost]
+ public IHttpActionResult Test2()
+ {
+ return DisplayJSON("");
+ }
+ }
+}
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Controllers/GateController.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Controllers/GateController.cs
new file mode 100644
index 0000000..8b82431
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Controllers/GateController.cs
@@ -0,0 +1,25 @@
+using Ewide.Core.DTO;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+
+namespace Ewide.Core.WebApi.Areas.Base.Controllers
+{
+ [ValidateArgumentsFilter]
+ public class GateController : BaseController
+ {
+ ///
+ /// 登录
+ ///
+ ///
+ ///
+ [ValidateArgumentsFilter(AllowNull = true)]
+ public IHttpActionResult Login(LoginDTO dto)
+ {
+ return DisplayJSON(dto);
+ }
+ }
+}
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Views/web.config b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Views/web.config
new file mode 100644
index 0000000..65f2f0a
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Base/Views/web.config
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/HelpPage/App_Start/HelpPageConfig.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/HelpPage/App_Start/HelpPageConfig.cs
index 762aba3..99219dd 100644
--- a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/HelpPage/App_Start/HelpPageConfig.cs
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/HelpPage/App_Start/HelpPageConfig.cs
@@ -34,7 +34,7 @@ namespace Ewide.Core.WebApi.Areas.HelpPage
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
- //config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
+ config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/Ewide.Core.WebApi.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable. The sample objects will be serialized into different media type
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Manage/Controllers/AreaTestController.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Manage/Controllers/AreaTestController.cs
new file mode 100644
index 0000000..f93d7f5
--- /dev/null
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Areas/Manage/Controllers/AreaTestController.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+
+namespace Ewide.Core.WebApi.Areas.Manage.Controllers
+{
+ public class AreaTestController : BaseController
+ {
+ ///
+ /// 区域测试
+ ///
+ ///
+ public IHttpActionResult Test()
+ {
+ return DisplayJSON("1");
+ }
+ }
+}
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/BaseController.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/BaseController.cs
index 58e98f1..91acc3c 100644
--- a/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/BaseController.cs
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/BaseController.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
+using System.Text;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Results;
@@ -15,7 +16,7 @@ namespace Ewide.Core.WebApi
{
protected override void Initialize(HttpControllerContext controllerContext)
{
- //base.Initialize(controllerContext);
+ base.Initialize(controllerContext);
}
protected override ExceptionResult InternalServerError(Exception exception)
diff --git a/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/ValidateArgumentsFilter.cs b/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/ValidateArgumentsFilter.cs
index 6a58298..d955404 100644
--- a/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/ValidateArgumentsFilter.cs
+++ b/Api/Ewide.Core/Ewide.Core.WebApi/Controllers/Code/ValidateArgumentsFilter.cs
@@ -13,9 +13,25 @@ namespace Ewide.Core.WebApi
{
public class ValidateArgumentsFilter : ActionFilterAttribute
{
+ public bool AllowNull { get; set; } = false;
public override void OnActionExecuting(HttpActionContext actionContext)
{
+ if (!AllowNull)
+ {
+ foreach (var arg in actionContext.ActionArguments)
+ {
+ if (arg.Value == null)
+ {
+ actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK,
+ BaseDisplayJSON.DisplayJSON(BaseDisplayJSON.Display(HttpStatusCode.BadRequest, "参数不可为空"))
+ );
+ break;
+ }
+ }
+ }
+
+
if (!actionContext.ModelState.IsValid)
{
var message = new List
-
+
+
@@ -250,17 +255,18 @@
+
-
- {9003B29C-AC1D-444E-8FE2-201F76D848A5}
- Ewide.Core.DTO
-
{c7e2ac14-ac20-4552-a5b8-08b650ac8416}
Ewide.Core.Common
+
+ {590704FF-28C5-4536-B587-AC213858CC42}
+ Ewide.Core.DTO
+
{34ae80c2-5c37-4b6c-aac3-f52c06928721}
Ewide.Core.Service
diff --git a/Api/Ewide.Core/Ewide.Core.sln b/Api/Ewide.Core/Ewide.Core.sln
index 629506c..b4846c4 100644
--- a/Api/Ewide.Core/Ewide.Core.sln
+++ b/Api/Ewide.Core/Ewide.Core.sln
@@ -17,12 +17,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Core.Utility", "Ewide
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Core.Service", "Ewide.Core.Service\Ewide.Core.Service.csproj", "{34AE80C2-5C37-4B6C-AAC3-F52C06928721}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Core.DTO", "Ewide.Core.Arguments\Ewide.Core.DTO.csproj", "{9003B29C-AC1D-444E-8FE2-201F76D848A5}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Core.Common", "Ewide.Core.Common\Ewide.Core.Common.csproj", "{C7E2AC14-AC20-4552-A5B8-08B650AC8416}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Core.Data", "Ewide.Core.Data\Ewide.Core.Data.csproj", "{B5B46BAD-81E3-4DF0-83EF-75148236F7CE}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Core.DTO", "Ewide.Core.DTO\Ewide.Core.DTO.csproj", "{590704FF-28C5-4536-B587-AC213858CC42}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -45,10 +45,6 @@ Global
{34AE80C2-5C37-4B6C-AAC3-F52C06928721}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34AE80C2-5C37-4B6C-AAC3-F52C06928721}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34AE80C2-5C37-4B6C-AAC3-F52C06928721}.Release|Any CPU.Build.0 = Release|Any CPU
- {9003B29C-AC1D-444E-8FE2-201F76D848A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9003B29C-AC1D-444E-8FE2-201F76D848A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9003B29C-AC1D-444E-8FE2-201F76D848A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9003B29C-AC1D-444E-8FE2-201F76D848A5}.Release|Any CPU.Build.0 = Release|Any CPU
{C7E2AC14-AC20-4552-A5B8-08B650AC8416}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7E2AC14-AC20-4552-A5B8-08B650AC8416}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7E2AC14-AC20-4552-A5B8-08B650AC8416}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -57,6 +53,10 @@ Global
{B5B46BAD-81E3-4DF0-83EF-75148236F7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5B46BAD-81E3-4DF0-83EF-75148236F7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5B46BAD-81E3-4DF0-83EF-75148236F7CE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {590704FF-28C5-4536-B587-AC213858CC42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {590704FF-28C5-4536-B587-AC213858CC42}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {590704FF-28C5-4536-B587-AC213858CC42}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {590704FF-28C5-4536-B587-AC213858CC42}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -65,9 +65,9 @@ Global
{31C3CA3D-14A1-453A-866D-76D4C74A9BDC} = {30FD9EAF-7D70-4244-83AD-EB702BDC95ED}
{D5C48D01-5AB1-44C9-8709-D4A336D19E9F} = {2D369B73-E5F6-412B-AD86-C5D1384D815B}
{34AE80C2-5C37-4B6C-AAC3-F52C06928721} = {62222202-F9F0-4E0A-9C7F-CB69CBE60611}
- {9003B29C-AC1D-444E-8FE2-201F76D848A5} = {30FD9EAF-7D70-4244-83AD-EB702BDC95ED}
{C7E2AC14-AC20-4552-A5B8-08B650AC8416} = {2D369B73-E5F6-412B-AD86-C5D1384D815B}
{B5B46BAD-81E3-4DF0-83EF-75148236F7CE} = {30FD9EAF-7D70-4244-83AD-EB702BDC95ED}
+ {590704FF-28C5-4536-B587-AC213858CC42} = {30FD9EAF-7D70-4244-83AD-EB702BDC95ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {435CD121-36FA-41DC-95FE-0B93517A1190}