├── README.md ├── API_1 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── Controllers │ └── FigureController.cs ├── API_2 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── Controllers │ └── FigureController.cs ├── API_3 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Models │ └── Clone │ │ ├── HttpActionResult.cs │ │ └── ApiController.cs └── Web.config ├── API_4 ├── Global.asax ├── Models │ ├── Direwolf.cs │ ├── Figure.cs │ └── FigureManager.cs ├── Global.asax.cs ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── Controllers │ └── FigureController.cs ├── API_6 ├── Global.asax ├── packages │ ├── repositories.config │ └── Microsoft.AspNet.WebApi.5.2.2 │ │ └── Microsoft.AspNet.WebApi.5.2.2.nupkg ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Global.asax.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── MyHttpMessageHandler.cs ├── Controllers │ └── DemoController.cs └── Web.config ├── API_7 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── Controllers │ ├── HttpConfigurationExtensions.cs │ ├── AttrController.cs │ └── DemoController.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── App_Start │ └── WebApiConfig.cs └── Web.config ├── API_8 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── Controllers │ ├── MyValueProviderFactory.cs │ ├── MyExceptionHandler.cs │ └── DemoController.cs ├── App_Start │ └── WebApiConfig.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config └── Web.config ├── API_9 ├── Global.asax ├── Services │ ├── IPrintService.cs │ ├── PinsPrintService.cs │ └── LaserPrintService.cs ├── Controllers │ └── DemoController.cs ├── Global.asax.cs ├── packages.config ├── App_Start │ ├── WebApiConfig.cs │ └── UnityDependencyResolver.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config └── Web.config ├── API_11 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Validator │ ├── ArrayValidationAttribute.cs │ └── ArrayValidator.cs ├── Controllers │ └── DemoController.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config └── Web.config ├── API_12 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── Controllers │ └── DemoController.cs ├── App_Start │ └── WebApiConfig.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── MyActionResult.cs └── Web.config ├── API_13 ├── Global.asax ├── Global.asax.cs ├── packages.config ├── App_Start │ ├── ActionFilter.cs │ ├── ControllerFilter.cs │ ├── GlobalFilter.cs │ ├── WebApiConfig.cs │ ├── FilterMessageHandler.cs │ ├── RequestActionFilterAttribute.cs │ └── ExceptionFilter.cs ├── Controllers │ ├── SingleFilterController.cs │ ├── OverrideFilterController.cs │ ├── FilterOrderController.cs │ └── ExceptionController.cs ├── Models │ └── FilterModel.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── HttpRequestMessageHelper.cs └── Web.config ├── API_15 ├── Global.asax ├── packages.config ├── App_Start │ └── WebApiConfig.cs ├── Global.asax.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Controllers │ └── DemoController.cs └── Web.config ├── API_15.Web ├── Global.asax ├── Global.asax.cs ├── Controllers │ └── HomeController.cs ├── App_Start │ └── RouteConfig.cs ├── packages.config ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Views │ ├── web.config │ └── Home │ │ └── Index.cshtml └── Web.config ├── FilterChannelDemo ├── App.config ├── AsyncVoid.cs ├── ActionExecutor.cs ├── ResponseMessage.cs ├── IActionFilter.cs ├── Controller.cs ├── FirstActionFilter.cs ├── SecondActionFilter.cs ├── ActionContext.cs ├── Properties │ └── AssemblyInfo.cs ├── ExpressionTree.cs ├── Program.cs ├── ActionFilter.cs ├── ActionInvoker.cs ├── TaskHelpers.cs └── FilterChannelDemo.csproj ├── Model ├── packages.config ├── Figure.cs ├── FigureManager.cs ├── Properties │ └── AssemblyInfo.cs └── Model.csproj ├── .gitattributes └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # WebAPI 2 | WebAPI 学习 3 | 本项目的博客地址http://www.cnblogs.com/gangtianci/ 4 | -------------------------------------------------------------------------------- /API_1/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_1.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_2/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_2.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_3/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_3.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_4/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_4.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_6/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_6.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_7/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_7.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_8/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_8.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_9/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_9.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_11/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_11.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_12/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_12.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_13/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_13.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_15/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_15.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_15.Web/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="API_15.Web.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /API_6/packages/repositories.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /API_6/packages/Microsoft.AspNet.WebApi.5.2.2/Microsoft.AspNet.WebApi.5.2.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarlowDu/WebAPI/HEAD/API_6/packages/Microsoft.AspNet.WebApi.5.2.2/Microsoft.AspNet.WebApi.5.2.2.nupkg -------------------------------------------------------------------------------- /FilterChannelDemo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /API_9/Services/IPrintService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_9.Services 7 | { 8 | public interface IPrintService 9 | { 10 | string Print(); 11 | } 12 | } -------------------------------------------------------------------------------- /FilterChannelDemo/AsyncVoid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | internal struct AsyncVoid 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /API_4/Models/Direwolf.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_4.Models 7 | { 8 | public class Direwolf 9 | { 10 | public string Name { get; set; } 11 | public string Color { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /FilterChannelDemo/ActionExecutor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | //public class ActionExecutor 10 | //{ 11 | // public void E 12 | //} 13 | } 14 | -------------------------------------------------------------------------------- /FilterChannelDemo/ResponseMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | public class ResponseMessage 10 | { 11 | public string Message { get;set;} 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /API_9/Services/PinsPrintService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_9.Services 7 | { 8 | public class PinsPrintService : IPrintService 9 | { 10 | public string Print() 11 | { 12 | return "这是一台针式打印机"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /API_9/Services/LaserPrintService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_9.Services 7 | { 8 | public class LaserPrintService : IPrintService 9 | { 10 | public string Print() 11 | { 12 | return "这是一台激光打印机"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /API_1/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_1 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_11/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_11 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_12/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_12 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_13/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_13 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_2/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_2 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_3/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_3 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_4/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_4 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_7/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_7 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /API_8/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_8 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /FilterChannelDemo/IActionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace FilterChannelDemo 9 | { 10 | public interface IActionFilter 11 | { 12 | Task ExecuteActionFilterAsync(ActionContext actionContext, CancellationToken cancellationToken, Func> continuation); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /API_15.Web/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace API_15.Web 9 | { 10 | public class MvcApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | AreaRegistration.RegisterAllAreas(); 15 | RouteConfig.RegisterRoutes(RouteTable.Routes); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /API_1/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_11/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_12/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_13/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_15.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace API_15.Web.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | // GET: Home 12 | public ActionResult Index() 13 | { 14 | return View(); 15 | } 16 | 17 | public ActionResult Test() 18 | { 19 | return View(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /API_2/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_3/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_4/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_6/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_7/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_8/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Model/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /API_13/App_Start/ActionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_13 7 | { 8 | 9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 10 | public class ActionFilterFirstAttribute : RequestActionFilterAttribute 11 | { 12 | } 13 | 14 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 15 | public class ActionFilterSecondAttribute : RequestActionFilterAttribute 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /API_8/Controllers/MyValueProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http.ValueProviders; 6 | 7 | namespace API_8.Controllers 8 | { 9 | public class MyValueProviderFactory : ValueProviderFactory 10 | { 11 | 12 | public override IValueProvider GetValueProvider(System.Web.Http.Controllers.HttpActionContext actionContext) 13 | { 14 | throw new NotImplementedException(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /API_13/App_Start/ControllerFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_13 7 | { 8 | 9 | [AttributeUsage(AttributeTargets.Class,AllowMultiple=false)] 10 | public class ControllerFilterFirstAttribute:RequestActionFilterAttribute 11 | { 12 | } 13 | 14 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 15 | public class ControllerFilterSecondAttribute : RequestActionFilterAttribute 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /API_13/App_Start/GlobalFilter.cs: -------------------------------------------------------------------------------- 1 | using API_13.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | using System.Web.Http.Filters; 7 | 8 | namespace API_13 9 | { 10 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)] 11 | public class GlobalFilterFirstAttribute : RequestActionFilterAttribute 12 | { 13 | 14 | } 15 | 16 | public class GlobalFilterSecondAttribute : RequestActionFilterAttribute 17 | { 18 | } 19 | } -------------------------------------------------------------------------------- /FilterChannelDemo/Controller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | public class Controller 10 | { 11 | public ResponseMessage Get() 12 | { 13 | Console.WriteLine("Action Executing"); 14 | return new ResponseMessage() { Message = "Hello World" }; 15 | } 16 | 17 | public void Get1() 18 | { 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /API_8/Controllers/MyExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using System.Web.Http.ExceptionHandling; 8 | 9 | namespace API_8.Controllers 10 | { 11 | public class MyExceptionHandler : IExceptionHandler 12 | { 13 | public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /API_9/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using API_9.Services; 2 | using Microsoft.Practices.Unity; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Http; 8 | using System.Web.Http; 9 | 10 | namespace API_9.Controllers 11 | { 12 | public class DemoController : ApiController 13 | { 14 | [Dependency] 15 | public IPrintService printer{get;set;} 16 | public string Print() 17 | { 18 | return printer.Print(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /API_13/Controllers/SingleFilterController.cs: -------------------------------------------------------------------------------- 1 | using API_13.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | 9 | namespace API_13.Controllers 10 | { 11 | /*************唯一性测试********/ 12 | [GlobalFilterFirst] 13 | public class SingleFilterController : ApiController 14 | { 15 | 16 | [GlobalFilterFirst] 17 | public void Get() 18 | { 19 | HttpRequestMessageHelper.Add(Request, new FilterModel() { Message = "Action" }); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /API_13/Controllers/OverrideFilterController.cs: -------------------------------------------------------------------------------- 1 | using API_13.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | 9 | namespace API_13.Controllers 10 | { 11 | /******OverrideFilter测试********/ 12 | public class OverrideFilterController : ApiController 13 | { 14 | [GlobalFilterSecond] 15 | [OverrideActionFilters] 16 | public void Get() 17 | { 18 | HttpRequestMessageHelper.Add(Request,new FilterModel(this.GetType(),null)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Model/Figure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Web.Http.ModelBinding; 7 | 8 | namespace Model 9 | { 10 | [ModelBinder] 11 | public class Figure 12 | { 13 | public Figure() 14 | { } 15 | public Figure(string firstName, string lastName) 16 | { 17 | this.FirstName = firstName; 18 | this.LastName = lastName; 19 | } 20 | public string FirstName { get; set; } 21 | public string LastName { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /API_12/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | 2 | using Model; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Http; 8 | using System.Web.Http; 9 | 10 | namespace API_12.Controllers 11 | { 12 | public class DemoController : ApiController 13 | { 14 | public IHttpActionResult Get() 15 | { 16 | return MyOk(FigureManager.Figures); 17 | } 18 | 19 | public MyContentNegotiationResult MyOk(T content) 20 | { 21 | return new MyContentNegotiationResult(content, this); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_9/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using API_9.App_Start; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | using System.Web.Http; 7 | using System.Web.Routing; 8 | 9 | namespace API_9 10 | { 11 | public class WebApiApplication : System.Web.HttpApplication 12 | { 13 | protected void Application_Start() 14 | { 15 | GlobalConfiguration.Configure(WebApiConfig.Register); 16 | GlobalConfiguration.Configure(config => { 17 | config.DependencyResolver = UnityDependencyResolver.Instance; 18 | }); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /FilterChannelDemo/FirstActionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | public class FirstActionFilter : ActionFilter 10 | { 11 | public override void OnActionExecuting(ActionContext actionContext) 12 | { 13 | Console.WriteLine("FirstActionFilter Executing"); 14 | } 15 | public override void OnActionExecuted(ActionContext actionContext) 16 | { 17 | Console.WriteLine("FirstActionFilter Executed"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /FilterChannelDemo/SecondActionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | public class SecondActionFilter : ActionFilter 10 | { 11 | public override void OnActionExecuting(ActionContext actionContext) 12 | { 13 | Console.WriteLine("SecondActionFilter Executing"); 14 | } 15 | public override void OnActionExecuted(ActionContext actionContext) 16 | { 17 | Console.WriteLine("SecondActionFilter Executed"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /API_9/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /API_4/Models/Figure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http.ModelBinding; 6 | 7 | namespace API_4.Models 8 | { 9 | [ModelBinder] 10 | public class Figure 11 | { 12 | public Figure() 13 | { } 14 | public Figure(string firstName, string lastName) 15 | { 16 | this.FirstName = firstName; 17 | this.LastName = lastName; 18 | } 19 | public string FirstName { get; set; } 20 | public string LastName { get; set; } 21 | 22 | //用于复杂类型测试 23 | public Direwolf Direwolf { get; set; } 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /API_1/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_1 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_11/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_11 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_12/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_12 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_13/Controllers/FilterOrderController.cs: -------------------------------------------------------------------------------- 1 | using API_13.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | 9 | namespace API_13.Controllers 10 | { 11 | /**************Action执行顺序测试*****************/ 12 | [ControllerFilterFirst] 13 | [ControllerFilterSecond] 14 | public class FilterOrderController : ApiController 15 | { 16 | [ActionFilterFirst] 17 | [ActionFilterSecond] 18 | public void Get() 19 | { 20 | HttpRequestMessageHelper.Add(Request, new FilterModel() { Message = "Action" }); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /API_3/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_3 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_4/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_4 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_6/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_6 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_8/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_8 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_9/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_9 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_15.Web/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace API_15.Web 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /API_15/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /FilterChannelDemo/ActionContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace FilterChannelDemo 9 | { 10 | public class ActionContext 11 | { 12 | public ActionContext() 13 | { 14 | Messages = new List(); 15 | } 16 | public ResponseMessage Response { get; set; } 17 | public List Messages { get; set; } 18 | 19 | public Controller Controller { get; set; } 20 | 21 | public object[] Arguments { get; set; } 22 | 23 | public MethodInfo Action { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /API_6/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace API_6 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | GlobalConfiguration.Configure(t => t.MessageHandlers.Add(new HttpMethodChangeHandler())); 16 | //GlobalConfiguration.Configure(t => t.MessageHandlers.Add(new AllBackHttpMessageHandler())); 17 | //GlobalConfiguration.DefaultServer 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /API_15/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_15 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | config.EnableCors(); 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{action}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API_7/Controllers/HttpConfigurationExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Web; 6 | using System.Web.Http; 7 | using System.Web.Http.Routing; 8 | 9 | namespace API_7.Controllers 10 | { 11 | public static class HttpConfigurationExtensions 12 | { 13 | public static IDictionary GetRouteMapping(this HttpConfiguration config) 14 | { 15 | FieldInfo field = typeof(HttpRouteCollection).GetField("_dictionary", BindingFlags.NonPublic | BindingFlags.Instance); 16 | var val = field.GetValue(config.Routes); 17 | return (Dictionary)val; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /API_2/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_2 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | //routeTemplate: "api/{controller}/{id}", 20 | routeTemplate: "api/{controller}/{action}/{id}", 21 | defaults: new { id = RouteParameter.Optional } 22 | ); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /API_15/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | using System.Web.Cors; 8 | using System.Web.Http.Cors; 9 | 10 | namespace API_15 11 | { 12 | public class WebApiApplication : System.Web.HttpApplication 13 | { 14 | protected void Application_Start() 15 | { 16 | 17 | GlobalConfiguration.Configuration.EnableCors(); 18 | GlobalConfiguration.Configure(WebApiConfig.Register); 19 | //GlobalConfiguration.Configuration.Properties["MS_CorsEnabledKey"]=true; 20 | //GlobalConfiguration.Configuration.MessageHandlers.Add(new CorsMessageHandler( GlobalConfiguration.Configuration)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /API_13/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace API_13 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | 13 | // Web API 配置和服务 14 | config.MessageHandlers.Add(new FilterMessageHandler()); 15 | 16 | config.Filters.Add(new GlobalFilterFirstAttribute()); 17 | // Web API 路由 18 | config.MapHttpAttributeRoutes(); 19 | 20 | config.Routes.MapHttpRoute( 21 | name: "DefaultApi", 22 | routeTemplate: "api/{controller}/{action}/{id}", 23 | defaults: new { id = RouteParameter.Optional } 24 | ); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /API_15.Web/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /API_4/Models/FigureManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_4.Models 7 | { 8 | public static class FigureManager 9 | { 10 | static List figures; 11 | static FigureManager() 12 | { 13 | figures = new List(); 14 | figures.Add(new Figure("Eddard", "Stack")); 15 | figures.Add(new Figure("Robb", "Stack")); 16 | figures.Add(new Figure("Sansa", "Stack")); 17 | figures.Add(new Figure("Arya", "Stack")); 18 | figures.Add(new Figure("Bran", "Stack")); 19 | figures.Add(new Figure("Rickon", "Stack")); 20 | figures.Add(new Figure("Jon", "Snow")); 21 | } 22 | public static List Figures 23 | { 24 | get { return figures; } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /API_11/Validator/ArrayValidationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace API_11.Validator 8 | { 9 | public class ArrayValidationAttribute : ValidationAttribute 10 | { 11 | public object[] _list; 12 | 13 | 14 | public ArrayValidationAttribute(params object[] list) 15 | { 16 | _list = list; 17 | } 18 | public object[] List 19 | { 20 | get { return _list; } 21 | set { _list = value; } 22 | } 23 | public override bool IsValid(object value) 24 | { 25 | return _list.Contains(value); 26 | } 27 | 28 | public override string FormatErrorMessage(string name) 29 | { 30 | return string.Format("{0}不在区间内.", name); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Model/FigureManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Model 8 | { 9 | public static class FigureManager 10 | { 11 | static List figures; 12 | static FigureManager() 13 | { 14 | figures = new List(); 15 | figures.Add(new Figure("Eddard", "Stack")); 16 | figures.Add(new Figure("Robb", "Stack")); 17 | figures.Add(new Figure("Sansa", "Stack")); 18 | figures.Add(new Figure("Arya", "Stack")); 19 | figures.Add(new Figure("Bran", "Stack")); 20 | figures.Add(new Figure("Rickon", "Stack")); 21 | figures.Add(new Figure("Jon", "Snow")); 22 | } 23 | public static List Figures 24 | { 25 | get { return figures; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /API_13/Models/FilterModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http.Filters; 6 | 7 | namespace API_13.Models 8 | { 9 | public class FilterModel 10 | { 11 | public string FilterTypeName { get; set; } 12 | public FilterScope? FilterScope { get; set; } 13 | 14 | public string Message { get; set; } 15 | 16 | public FilterModel() 17 | { } 18 | public FilterModel(Type filterType, FilterScope? filterScope) 19 | { 20 | FilterTypeName = filterType.FullName; 21 | FilterScope = filterScope; 22 | } 23 | 24 | public FilterModel(Type filterType, FilterScope? filterScope, string message) 25 | { 26 | FilterTypeName = filterType.FullName; 27 | FilterScope = filterScope; 28 | Message = message; 29 | } 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /API_11/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | using System.Web.Http.ModelBinding; 9 | 10 | namespace API_11.Controllers 11 | { 12 | public class DemoController : ApiController 13 | { 14 | public Figure PostFigureFromUrl([ModelBinder]Figure figure) 15 | { 16 | return figure; 17 | } 18 | 19 | public Figure PostFigureFromBody([FromBody]Figure figure) 20 | { 21 | return figure; 22 | } 23 | 24 | public ModelStateDictionary PostFigureFromUrlForState([ModelBinder]Figure figure) 25 | { 26 | return ModelState; 27 | } 28 | 29 | public ModelStateDictionary PostFigureFromBodyForState([FromBody]Figure figure) 30 | { 31 | return ModelState; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /API_1/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_1")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_1")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("5d8e85ab-78cb-4f7d-b50c-9ef1a7574323")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_11/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_11")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_11")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("680094fa-725d-420a-88d3-3cc22a9c9060")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_12/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_12")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_12")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("41afdfd3-752c-467c-93c9-7faca127c9e9")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_2")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_2")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("0565e7a7-e234-42ca-bc39-fae13377720d")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_3/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_3")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_3")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("4b8156a7-539d-49e4-a772-93196eb93296")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_4/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_4")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_4")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("f6a10a6b-119b-48e4-8dcb-da5bf7d5ee4d")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_6/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_6")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_6")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("4db70612-3ad0-4dd1-884e-b16e90e42384")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_7/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_7")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_7")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("0f1e12ea-92eb-47a8-b77b-7f98ba434d2e")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_8/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_8")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_8")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("3c61cd0e-a097-41a0-8916-5d613e948d24")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_9/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_9")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("API_9")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("112a4a2f-6934-4915-9032-8d7bd12e7843")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_13/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_13")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("API_13")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("3a3daea6-7410-49fb-9a37-820afd1e803d")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_15/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_15")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("API_15")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("96f17b39-9b34-4bfa-92d0-53fff5f06fef")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /API_15.Web/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("API_15.Web")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("API_15.Web")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("b3f6d714-0d9b-4975-8b1e-9de791ece6aa")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Model/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Model")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Model")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("fceadeb3-b2d3-465e-95b0-843704f00603")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /API_1/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_11/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_12/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_13/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_15/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_2/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_3/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_4/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_6/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_7/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_8/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_9/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_15.Web/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /API_7/Controllers/AttrController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Reflection; 7 | using System.Web.Http; 8 | using System.Web.Http.Routing; 9 | 10 | namespace API_7.Controllers 11 | { 12 | [RoutePrefix("api")] 13 | public class AttrController : ApiController 14 | { 15 | [Route("AttrRoute/GetAllRoute")] 16 | public List GetAttrRoutes() 17 | { 18 | List result = new List(); 19 | IEnumerable routes = (IEnumerable)RequestContext.Configuration.Routes["MS_attributerouteWebApi"]; 20 | foreach (var route in routes) 21 | { 22 | result.Add(route.RouteTemplate); 23 | } 24 | return result; 25 | } 26 | 27 | [Route("AttrRoute/Test/Get")] 28 | [Route("AttrRoute/Test/Post")] 29 | [Route("AttrRoute/Test/Put")] 30 | [Route("AttrRoute/Test/Delete")] 31 | public string Test() 32 | { 33 | return null; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /FilterChannelDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("FilterChannelDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("FilterChannelDemo")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("82c273cc-1dcc-4449-88f1-3929467a34c4")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /API_1/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_11/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_12/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_13/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_15/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_2/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_3/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_4/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_6/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_7/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_8/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_9/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_15.Web/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /API_15/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Web.Http; 7 | using System.Web.Http.Cors; 8 | using Model; 9 | using System.Text; 10 | using Newtonsoft.Json; 11 | 12 | namespace API_15.Controllers 13 | { 14 | public class DemoController : ApiController 15 | { 16 | public HttpResponseMessage GetFigureByJsonP(string callback) 17 | { 18 | StringBuilder result = new StringBuilder(); 19 | 20 | result.Append("callback("); 21 | result.Append(JsonConvert.SerializeObject(FigureManager.Figures)); 22 | result.Append(")"); 23 | return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(result.ToString()) }; 24 | } 25 | 26 | public IEnumerable GetFigureNoCors() 27 | { 28 | return FigureManager.Figures; 29 | } 30 | 31 | //[EnableCors(origins:"*",headers: "*",methods:"*")] 32 | [EnableCors(origins: "http://localhost:64299,http://www.baidu.com", headers: "GET,POST", methods: "*")] 33 | public IEnumerable GetFigureByCors() 34 | { 35 | return FigureManager.Figures; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /API_13/App_Start/FilterMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Threading.Tasks; 7 | using System.Web; 8 | 9 | namespace API_13 10 | { 11 | public class FilterMessageHandler : DelegatingHandler 12 | { 13 | protected override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) 14 | { 15 | request.Properties.Add("Response_Content", new List()); 16 | HttpRequestMessageHelper.Init(request); 17 | HttpResponseMessage response = base.SendAsync(request, cancellationToken).Result; 18 | GetResponseMessageFromRequest(request, response); 19 | return Task.FromResult(response); 20 | } 21 | 22 | private void GetResponseMessageFromRequest(HttpRequestMessage request, HttpResponseMessage response) 23 | { 24 | if (response.StatusCode == HttpStatusCode.OK || 25 | response.StatusCode == HttpStatusCode.NoContent|| 26 | response.StatusCode == HttpStatusCode.InternalServerError) 27 | { 28 | response.StatusCode = HttpStatusCode.OK; 29 | response.Content = HttpRequestMessageHelper.GetContent(request); 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /API_12/MyActionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Net.Http.Formatting; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using System.Web; 10 | using System.Web.Http; 11 | 12 | namespace API_12 13 | { 14 | public class MyContentNegotiationResult : IHttpActionResult 15 | { 16 | 17 | public MyContentNegotiationResult(T content, ApiController _controller) 18 | { 19 | Content = content; 20 | configuration = _controller.Configuration; 21 | request = _controller.Request; 22 | } 23 | 24 | public T Content { get; private set; } 25 | 26 | private HttpConfiguration configuration; 27 | private HttpRequestMessage request; 28 | public Task ExecuteAsync(CancellationToken cancellationToken) 29 | { 30 | IContentNegotiator negotiator = configuration.Services.GetContentNegotiator(); 31 | ContentNegotiationResult result=negotiator.Negotiate(typeof(T), request, configuration.Formatters); 32 | HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); 33 | response.Content = new ObjectContent(typeof(T), Content, result.Formatter); 34 | return Task.FromResult(response); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /API_7/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Web.Http; 6 | using System.Web.Http.Routing; 7 | using System.Web.Http.Routing.Constraints; 8 | 9 | namespace API_7 10 | { 11 | public static class WebApiConfig 12 | { 13 | public static void Register(HttpConfiguration config) 14 | { 15 | // Web API 配置和服务 16 | 17 | // Web API 路由 18 | config.MapHttpAttributeRoutes(); 19 | 20 | config.Routes.MapHttpRoute( 21 | name: "DefaultApi", 22 | routeTemplate: "api/{controller}/{action}/{id}", 23 | defaults: new { id = RouteParameter.Optional }//, 24 | //constraints:new{sss=new HttpMethodConstraint(HttpMethod.Post)} 25 | 26 | ); 27 | HttpRouteValueDictionary defaults = new HttpRouteValueDictionary(); 28 | //defaults.Add("controller", "Demo"); 29 | //defaults.Add("action", "Get"); 30 | defaults.Add("val", 0); 31 | HttpRouteValueDictionary constraints = new HttpRouteValueDictionary(); 32 | constraints.Add("val",new DoubleRouteConstraint()); 33 | 34 | HttpRoute route = new HttpRoute("customer/{controller}/{action}/{val}", defaults, constraints); 35 | 36 | config.Routes.Add("CustomerApi",route); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /API_11/Validator/ArrayValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Web; 6 | 7 | namespace API_11.Validator 8 | { 9 | public class ArrayValidator 10 | { 11 | /// 12 | /// 为CustomerValidationAttribute提供的验证方法(一个参数) 13 | /// 14 | /// 15 | /// 16 | public static ValidationResult Check(object val) 17 | { 18 | string[] list = new string[] { "Stack", "Other" }; 19 | if (list.Contains(val)) 20 | { 21 | return ValidationResult.Success; 22 | } 23 | else 24 | { 25 | return new ValidationResult("不在区间内"); 26 | } 27 | } 28 | 29 | /// 30 | /// 为CustomerValidationAttribute提供的验证方法(两个参数) 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static ValidationResult CheckString(string val, ValidationContext context) 36 | { 37 | string[] list = new string[] { "Stack", "Other" }; 38 | if (list.Contains(val)) 39 | { 40 | return ValidationResult.Success; 41 | } 42 | else 43 | { 44 | return new ValidationResult("不在区间内"); 45 | } 46 | } 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /API_6/MyHttpMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using System.Web.Http.Dispatcher; 8 | 9 | namespace API_6 10 | { 11 | public class HttpMethodChangeHandler : DelegatingHandler 12 | { 13 | protected override System.Threading.Tasks.Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) 14 | { 15 | var method = request.Method; 16 | if(request.Method == HttpMethod.Post) 17 | { 18 | request.Method = HttpMethod.Put; 19 | } 20 | else if(request.Method == HttpMethod.Put) 21 | { 22 | request.Method = HttpMethod.Post; 23 | } 24 | return base.SendAsync(request, cancellationToken); 25 | } 26 | 27 | 28 | } 29 | 30 | public class AllBackHttpMessageHandler : DelegatingHandler 31 | { 32 | protected override System.Threading.Tasks.Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) 33 | { 34 | return Task.Run(() => 35 | { 36 | HttpResponseMessage result = new HttpResponseMessage(System.Net.HttpStatusCode.OK); 37 | result.Content = new StringContent("AllHttpMessageHandler"); 38 | return result; 39 | 40 | 41 | }); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /API_13/HttpRequestMessageHelper.cs: -------------------------------------------------------------------------------- 1 | using API_13.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.Net.Http.Formatting; 7 | using System.Web; 8 | using System.Web.Http; 9 | 10 | namespace API_13 11 | { 12 | public class HttpRequestMessageHelper 13 | { 14 | public const string HeaderName = "Request_Content"; 15 | public static void Init(HttpRequestMessage request) 16 | { 17 | if (request.Properties.ContainsKey(HeaderName) == false) 18 | { 19 | request.Properties.Add(HeaderName, new List()); 20 | } 21 | } 22 | 23 | public static void Add(HttpRequestMessage request, FilterModel filterModel) 24 | { 25 | var requestMsg = (request.Properties[HeaderName] as List); 26 | if (requestMsg != null) 27 | { 28 | requestMsg.Add(filterModel); 29 | } 30 | } 31 | 32 | public static HttpContent GetContent(HttpRequestMessage request) 33 | { 34 | var requestMsg = (request.Properties[HeaderName] as List); 35 | HttpConfiguration configuration = request.GetConfiguration(); 36 | IContentNegotiator negotiator = configuration.Services.GetContentNegotiator(); 37 | var negotiatorResult = negotiator.Negotiate(typeof(List), request, configuration.Formatters); 38 | return new ObjectContent>(requestMsg, negotiatorResult.Formatter); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /API_6/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Web.Http; 7 | using System.Web.Http.Dispatcher; 8 | 9 | namespace API_6.Controllers 10 | { 11 | public class DemoController : ApiController 12 | { 13 | [HttpPost] 14 | public string Post() 15 | { 16 | return "这是一个Post方法"; 17 | } 18 | 19 | [HttpPut] 20 | public string Put() 21 | { 22 | return "这是一个Put方法"; 23 | } 24 | 25 | 26 | public IEnumerable GetChains() 27 | { 28 | 29 | IEnumerable result = GetChains(GlobalConfiguration.DefaultServer); 30 | 31 | 32 | return result; 33 | } 34 | 35 | private IEnumerable GetChains(DelegatingHandler handler) 36 | { 37 | yield return handler.GetType().FullName; 38 | var innerHander = handler.InnerHandler as DelegatingHandler; 39 | if (innerHander != null) 40 | { 41 | yield return innerHander.GetType().FullName; 42 | } 43 | 44 | } 45 | 46 | public IEnumerable CheckConfiguration() 47 | { 48 | //HttpRoutingDispatcher s = new HttpRoutingDispatcher(); 49 | List result = new List(); 50 | result.Add(GlobalConfiguration.Configuration.GetHashCode().ToString()); 51 | result.Add(this.Configuration.GetHashCode().ToString()); 52 | return result; 53 | } 54 | 55 | 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /API_9/App_Start/UnityDependencyResolver.cs: -------------------------------------------------------------------------------- 1 | using API_9.Controllers; 2 | using API_9.Services; 3 | using Microsoft.Practices.Unity; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Web; 8 | using System.Web.Http.Dependencies; 9 | 10 | namespace API_9.App_Start 11 | { 12 | public class UnityDependencyResolver : IDependencyResolver 13 | { 14 | static UnityDependencyResolver instance; 15 | IUnityContainer container = new UnityContainer(); 16 | private UnityDependencyResolver() 17 | { 18 | container.RegisterType(typeof(DemoController)); 19 | container.RegisterType(); 20 | } 21 | 22 | static UnityDependencyResolver() 23 | { 24 | instance = new UnityDependencyResolver(); 25 | } 26 | public static UnityDependencyResolver Instance 27 | { 28 | get { return instance; } 29 | } 30 | 31 | public IDependencyScope BeginScope() 32 | { 33 | return this; 34 | } 35 | 36 | public object GetService(Type serviceType) 37 | { 38 | try 39 | { 40 | return container.Resolve(serviceType); 41 | } 42 | catch 43 | { 44 | return null; 45 | } 46 | } 47 | 48 | public IEnumerable GetServices(Type serviceType) 49 | { 50 | return Enumerable.Empty(); 51 | } 52 | 53 | public void Dispose() 54 | { 55 | container.Dispose(); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /API_15.Web/Views/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /API_13/Controllers/ExceptionController.cs: -------------------------------------------------------------------------------- 1 | using API_13.App_Start; 2 | using API_13.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Http; 8 | using System.Web.Http; 9 | 10 | namespace API_13.Controllers 11 | { 12 | public class ExceptionController : ApiController 13 | { 14 | /*当Action本身抛出异常时,ActionFilter管道会继续执行,并最终进入ExceptionFilter管道*/ 15 | [ExceptionFilterFirst] 16 | [ActionFilterSecond] 17 | public void GetActionException() 18 | { 19 | HttpRequestMessageHelper.Add(Request, new FilterModel() { Message = "Action" }); 20 | throw new Exception("test"); 21 | } 22 | 23 | /*当ActionFilter的OnActionExecuting方法抛出异常时,ActionFilter管道结束执行,并进入ExceptionFilter管道*/ 24 | [ExceptionFilterFirst] 25 | [ExcutingExceptionActionFilter] 26 | public void GetActionFilterExecutingException() 27 | { 28 | HttpRequestMessageHelper.Add(Request, new FilterModel() { Message = "Action" }); 29 | } 30 | 31 | /*当ActionFilter的OnActionExecuted方法抛出异常时,ActionFilter管道会继续执行,并最终进入ExceptionFilter管道*/ 32 | [ExceptionFilterFirst] 33 | [ExcutedExceptionActionFilter] 34 | public void GetActionFilterExecutedException() 35 | { 36 | HttpRequestMessageHelper.Add(Request, new FilterModel() { Message = "Action" }); 37 | } 38 | 39 | 40 | /*当ExceptionFilter中抛出异常时,后续ExceptionFilter不会执行*/ 41 | [ExceptionFilterFirst] 42 | [ExceptionFilterThird] 43 | public void GetExceptionFilterError() 44 | { 45 | HttpRequestMessageHelper.Add(Request, new FilterModel() { Message = "Action" }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /API_13/App_Start/RequestActionFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http.Filters; 6 | using System.Reflection; 7 | using System.Web.Http.Controllers; 8 | using System.Web.Http; 9 | using API_13.Models; 10 | 11 | namespace API_13 12 | { 13 | public class RequestActionFilterAttribute : ActionFilterAttribute 14 | { 15 | public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) 16 | { 17 | //AuthorizationFilterAttribute 18 | //AuthorizeAttribute 19 | 20 | // OverrideActionFiltersAttribute 21 | HttpRequestMessageHelper.Add(actionContext.Request, new FilterModel(this.GetType(),GetFilterScope(actionContext.ActionDescriptor))); 22 | } 23 | 24 | public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) 25 | { 26 | HttpRequestMessageHelper.Add(actionExecutedContext.Request, 27 | new FilterModel(this.GetType(),GetFilterScope(actionExecutedContext.ActionContext.ActionDescriptor))); 28 | } 29 | 30 | protected FilterScope? GetFilterScope(HttpActionDescriptor descriptor) 31 | { 32 | HttpConfiguration configuration = descriptor.Configuration; 33 | var providers = configuration.Services.GetFilterProviders(); 34 | IEnumerable filterInfos; 35 | FilterInfo result = null; 36 | foreach (var provider in providers) 37 | { 38 | filterInfos = provider.GetFilters(configuration, descriptor); 39 | result = filterInfos.SingleOrDefault(t => t.Instance == this); 40 | if (result != null) 41 | { 42 | return result.Scope; 43 | } 44 | 45 | } 46 | 47 | return null; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /FilterChannelDemo/ExpressionTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace FilterChannelDemo 10 | { 11 | public class ExpressionTree 12 | { 13 | public static Func Exec(MethodInfo methodInfo) 14 | { 15 | //Func func = (instance, parames) => 16 | //{ 17 | // return (methodInfo.Invoke(instance, parames) as ResponseMessage); 18 | //}; 19 | 20 | ParameterExpression instanceParameter = Expression.Parameter(typeof(object), "instance"); 21 | ParameterExpression parametersParameter = Expression.Parameter(typeof(object[]), "paramters"); 22 | List parameters = new List(); 23 | ParameterInfo[] paramInfos = methodInfo.GetParameters(); 24 | 25 | for (int i = 0; i < paramInfos.Length; i++) 26 | { 27 | ParameterInfo paramInfo = paramInfos[i]; 28 | BinaryExpression valueObj = Expression.ArrayIndex(parametersParameter, Expression.Constant(i)); 29 | UnaryExpression valueCast = Expression.Convert(valueObj, paramInfo.ParameterType); 30 | 31 | parameters.Add(valueCast); 32 | } 33 | 34 | UnaryExpression instanceCast = Expression.Convert(instanceParameter, methodInfo.ReflectedType); 35 | MethodCallExpression methodCall = Expression.Call(instanceCast, methodInfo, parameters); 36 | UnaryExpression result = Expression.Convert(methodCall, typeof(object)); 37 | 38 | Expression> lambda = Expression.Lambda>(result, instanceParameter, parametersParameter); 39 | var func = lambda.Compile(); 40 | 41 | return func; 42 | 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /FilterChannelDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace FilterChannelDemo 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | Controller controller = new Controller(); 17 | MethodInfo actionMethod = typeof(Controller).GetMethod("Get"); 18 | 19 | CancellationToken cancellationToken = new CancellationToken(); 20 | 21 | List filters = new List() { 22 | new FirstActionFilter(), 23 | new SecondActionFilter() 24 | }; 25 | ActionContext context = new ActionContext() 26 | { 27 | Controller = controller, 28 | Action = actionMethod, 29 | Arguments = new object[0] 30 | }; 31 | ActionInvoker invoker = new ActionInvoker(context.Action); 32 | 33 | Func> result = () => 34 | { 35 | return invoker.Invoke(context, cancellationToken); 36 | }; 37 | 38 | for (int i = 0; i <= filters.Count - 1; i++) 39 | { 40 | IActionFilter filter = filters[i]; 41 | 42 | Func>, IActionFilter, Func>> chainContinuation = 43 | (continuation, innerFilter) => 44 | { 45 | return () => 46 | { 47 | return innerFilter.ExecuteActionFilterAsync(context, cancellationToken, continuation); 48 | }; 49 | }; 50 | result = chainContinuation(result, filter); 51 | } 52 | //string res = continuation()().Result.Message; 53 | result.Invoke(); 54 | Console.ReadKey(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /API_1/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /API_2/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /API_13/App_Start/ExceptionFilter.cs: -------------------------------------------------------------------------------- 1 | using API_13.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Web; 6 | using System.Web.Http.Filters; 7 | 8 | namespace API_13.App_Start 9 | { 10 | public class ExceptionFilterFirstAttribute : ExceptionFilterAttribute 11 | { 12 | public override void OnException(HttpActionExecutedContext actionExecutedContext) 13 | { 14 | HttpRequestMessageHelper.Add(actionExecutedContext.Request, 15 | new FilterModel() { FilterTypeName = this.GetType().FullName, Message = actionExecutedContext.Exception.Message }); 16 | } 17 | 18 | 19 | } 20 | 21 | public class ExceptionFilterThirdAttribute : ExceptionFilterAttribute 22 | { 23 | public override void OnException(HttpActionExecutedContext actionExecutedContext) 24 | { 25 | HttpRequestMessageHelper.Add(actionExecutedContext.Request, 26 | new FilterModel() { FilterTypeName = this.GetType().FullName, Message = actionExecutedContext.Exception.Message }); 27 | throw new Exception(); 28 | } 29 | 30 | 31 | } 32 | 33 | public class ExceptionFilterSecondAttribute : ExceptionFilterAttribute 34 | { 35 | public override void OnException(HttpActionExecutedContext actionExecutedContext) 36 | { 37 | HttpRequestMessageHelper.Add(actionExecutedContext.Request, 38 | new FilterModel() { FilterTypeName = this.GetType().FullName, Message = actionExecutedContext.Exception.Message }); 39 | } 40 | 41 | 42 | } 43 | 44 | 45 | public class ExcutingExceptionActionFilterAttribute : RequestActionFilterAttribute 46 | { 47 | public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) 48 | { 49 | base.OnActionExecuting(actionContext); 50 | throw new Exception("ExcutingExceptionActionFilterAttribute Error"); 51 | } 52 | } 53 | 54 | 55 | 56 | public class ExcutedExceptionActionFilterAttribute : RequestActionFilterAttribute 57 | { 58 | 59 | public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) 60 | { 61 | base.OnActionExecuted(actionExecutedContext); 62 | throw new Exception("ExcutingExceptionActionFilterAttribute Error"); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /FilterChannelDemo/ActionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace FilterChannelDemo 9 | { 10 | public abstract class ActionFilter : IActionFilter 11 | { 12 | public virtual void OnActionExecuting(ActionContext actionContext) 13 | { 14 | } 15 | 16 | public virtual void OnActionExecuted(ActionContext actionContext) 17 | { 18 | } 19 | 20 | public Task OnActionExecutingAsync(ActionContext actionContext) 21 | { 22 | OnActionExecuting(actionContext); 23 | 24 | return Task.FromResult(default(AsyncVoid)); 25 | } 26 | 27 | 28 | public Task OnActionExecutedAsync(ActionContext actionContext, CancellationToken cancellationToken) 29 | { 30 | OnActionExecuted(actionContext); 31 | return Task.FromResult(default(AsyncVoid)); 32 | } 33 | public Task ExecuteActionFilterAsync(ActionContext actionContext, System.Threading.CancellationToken cancellationToken, Func> continuation) 34 | { 35 | return ExecuteActionFilterAsyncCore(actionContext, cancellationToken, continuation); 36 | 37 | } 38 | private async Task ExecuteActionFilterAsyncCore(ActionContext actionContext, CancellationToken cancellationToken, Func> continuation) 39 | { 40 | await OnActionExecutingAsync(actionContext); 41 | 42 | if (actionContext.Response != null) 43 | { 44 | return actionContext.Response; 45 | } 46 | 47 | return await CallOnActionExecutedAsync(actionContext, cancellationToken, continuation); 48 | } 49 | 50 | private async Task CallOnActionExecutedAsync(ActionContext actionContext, CancellationToken cancellationToken, Func> continuation) 51 | { 52 | ResponseMessage response = null; ; 53 | try 54 | { 55 | response = await continuation(); 56 | } 57 | catch (Exception ex) 58 | { 59 | } 60 | await OnActionExecutedAsync(actionContext, cancellationToken); 61 | return response; 62 | //throw new NotImplementedException(); 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /FilterChannelDemo/ActionInvoker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace FilterChannelDemo 11 | { 12 | public class ActionInvoker 13 | { 14 | Func> executor; 15 | public ActionInvoker(MethodInfo methodInfo) 16 | { 17 | executor = GetExecutor(methodInfo); 18 | } 19 | public async Task Invoke(ActionContext context, CancellationToken cancellationToken) 20 | { 21 | return await executor(context.Controller, context.Arguments); 22 | } 23 | 24 | private Func> GetExecutor(MethodInfo methodInfo) 25 | { 26 | ParameterExpression instanceParameter = Expression.Parameter(typeof(object), "instance"); 27 | ParameterExpression parametersParameter = Expression.Parameter(typeof(object[]), "paramters"); 28 | List parameters = new List(); 29 | ParameterInfo[] paramInfos = methodInfo.GetParameters(); 30 | 31 | for (int i = 0; i < paramInfos.Length; i++) 32 | { 33 | ParameterInfo paramInfo = paramInfos[i]; 34 | BinaryExpression valueObj = Expression.ArrayIndex(parametersParameter, Expression.Constant(i)); 35 | UnaryExpression valueCast = Expression.Convert(valueObj, paramInfo.ParameterType); 36 | 37 | parameters.Add(valueCast); 38 | } 39 | 40 | UnaryExpression instanceCast = Expression.Convert(instanceParameter, methodInfo.ReflectedType); 41 | MethodCallExpression methodCall = Expression.Call(instanceCast, methodInfo, parameters); 42 | UnaryExpression result = Expression.Convert(methodCall, typeof(ResponseMessage)); 43 | 44 | Expression> lambda = Expression.Lambda>(result, instanceParameter, parametersParameter); 45 | 46 | var func1 = lambda.Compile(); 47 | 48 | Func> func = (instance, arguments) => 49 | { 50 | var response = func1(instance, arguments); 51 | return Task.FromResult(response); 52 | }; 53 | return func; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /API_3/Models/Clone/HttpActionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace API_3.Models.Clone 7 | { 8 | 9 | public interface IHttpActionResult 10 | { 11 | } 12 | public abstract class HttpActionResult : IHttpActionResult 13 | { 14 | } 15 | 16 | /// 17 | /// 自定义状态码 18 | /// 19 | public class CodeStatusResult : IHttpActionResult 20 | { 21 | } 22 | 23 | /// 24 | /// 400,Bad Request 25 | /// 26 | public class BadRequestResult : IHttpActionResult 27 | { 28 | } 29 | 30 | public class RedirectResult : IHttpActionResult 31 | { 32 | } 33 | 34 | /// 35 | /// 根据Formatter进行序列化 36 | /// 37 | public class FormattedContentResult : IHttpActionResult 38 | { 39 | } 40 | 41 | /// 42 | /// 分写请求头信息进行序列化 43 | /// 44 | public class NegotiatedContentResult : IHttpActionResult 45 | { 46 | } 47 | 48 | public class OkNegotiatedContentResult : IHttpActionResult 49 | { 50 | } 51 | 52 | public class ExceptionResult : IHttpActionResult 53 | { 54 | } 55 | 56 | public class BadRequestErrorMessageResult : IHttpActionResult 57 | { 58 | } 59 | 60 | public class InvalidModelStateResult : IHttpActionResult 61 | { 62 | } 63 | 64 | public class CreatedNegotiatedContentResult : IHttpActionResult 65 | { 66 | } 67 | 68 | public class CreatedAtRouteNegotiatedContentResult : IHttpActionResult 69 | { 70 | } 71 | 72 | public class JsonResult : IHttpActionResult 73 | { 74 | } 75 | 76 | public class RedirectToRouteResult 77 | { 78 | } 79 | 80 | /// 81 | /// 200,OK 82 | /// 83 | public class OkResult 84 | { 85 | } 86 | 87 | /// 88 | /// 404,Not Found 89 | /// 90 | public class NotFoundResult 91 | { 92 | } 93 | 94 | /// 95 | /// 401,UnAuthorizedResult(无授权) 96 | /// 97 | public class UnAuthorizedResult 98 | { 99 | } 100 | 101 | /// 102 | /// 409,Conflic(资源冲突) 103 | /// 104 | public class ConflictResult 105 | { 106 | } 107 | 108 | /// 109 | /// 500,Internal Server Error 110 | /// 111 | public class InternalServerErrorResult 112 | { 113 | } 114 | } -------------------------------------------------------------------------------- /API_1/Controllers/FigureController.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | 9 | namespace API_1.Controllers 10 | { 11 | public class FigureController : ApiController 12 | { 13 | 14 | public IEnumerable GetAll() 15 | { 16 | return FigureManager.Figures; 17 | } 18 | 19 | public Figure GetByQueryString(string firstName) 20 | { 21 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName); 22 | return result; 23 | } 24 | 25 | [Route("api/Figure/GetByRoute/{firstName}")] 26 | public Figure GetByRoute(string firstName) 27 | { 28 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName); 29 | return result; 30 | } 31 | 32 | public IEnumerable PostByUrl(string firstName, string lastName) 33 | { 34 | //Catelyn Tully 35 | FigureManager.Figures.Add(new Figure(firstName, lastName)); 36 | return FigureManager.Figures; 37 | } 38 | 39 | public IEnumerable PostByUrlModel(Figure figure) 40 | { 41 | //Catelyn Tully 42 | if (figure != null) 43 | { 44 | FigureManager.Figures.Add(figure); 45 | } 46 | return FigureManager.Figures; 47 | } 48 | 49 | [Route("api/Figure/PostByRouteModel/{FirstName}/{LastName}")] 50 | public IEnumerable PostByRouteModel(Figure figure) 51 | { 52 | //Catelyn Tully 53 | if (figure != null) 54 | { 55 | FigureManager.Figures.Add(figure); 56 | } 57 | return FigureManager.Figures; 58 | } 59 | 60 | public IEnumerable PostByBody([FromBody] Figure figure) 61 | { 62 | string body = Request.Content.ReadAsStringAsync().Result; 63 | if (figure != null) 64 | { 65 | FigureManager.Figures.Add(figure); 66 | } 67 | return FigureManager.Figures; 68 | } 69 | 70 | public IEnumerable Delete(string firstName) 71 | { 72 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName); 73 | if (result != null) 74 | { 75 | FigureManager.Figures.Remove(result); 76 | } 77 | return FigureManager.Figures; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /FilterChannelDemo/TaskHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FilterChannelDemo 8 | { 9 | internal class TaskHelpers 10 | { 11 | private static readonly Task _defaultCompleted = Task.FromResult(default(AsyncVoid)); 12 | 13 | private static readonly Task _completedTaskReturningNull = Task.FromResult(null); 14 | 15 | /// 16 | /// Returns a canceled Task. The task is completed, IsCanceled = True, IsFaulted = False. 17 | /// 18 | internal static Task Canceled() 19 | { 20 | return CancelCache.Canceled; 21 | } 22 | 23 | /// 24 | /// Returns a canceled Task of the given type. The task is completed, IsCanceled = True, IsFaulted = False. 25 | /// 26 | internal static Task Canceled() 27 | { 28 | return CancelCache.Canceled; 29 | } 30 | 31 | /// 32 | /// Returns a completed task that has no result. 33 | /// 34 | internal static Task Completed() 35 | { 36 | return _defaultCompleted; 37 | } 38 | 39 | internal static Task FromError(Exception exception) 40 | { 41 | return FromError(exception); 42 | } 43 | 44 | internal static Task FromError(Exception exception) 45 | { 46 | TaskCompletionSource tcs = new TaskCompletionSource(); 47 | tcs.SetException(exception); 48 | return tcs.Task; 49 | } 50 | 51 | internal static Task NullResult() 52 | { 53 | return _completedTaskReturningNull; 54 | } 55 | 56 | /// 57 | /// Used as the T in a "conversion" of a Task into a Task{T} 58 | /// 59 | private struct AsyncVoid 60 | { 61 | } 62 | 63 | /// 64 | /// This class is a convenient cache for per-type cancelled tasks 65 | /// 66 | private static class CancelCache 67 | { 68 | public static readonly Task Canceled = GetCancelledTask(); 69 | 70 | private static Task GetCancelledTask() 71 | { 72 | TaskCompletionSource tcs = new TaskCompletionSource(); 73 | tcs.SetCanceled(); 74 | return tcs.Task; 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /API_7/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Web.Http; 7 | using System.Web.Http.Routing; 8 | using System.Web.Http.Routing.Constraints; 9 | 10 | namespace API_7.Controllers 11 | { 12 | public class DemoController : ApiController 13 | { 14 | 15 | public string GetUrl() 16 | { 17 | return Request.RequestUri.AbsoluteUri; 18 | } 19 | 20 | //约束 21 | public double GetDouble(string val) 22 | { 23 | return double.Parse(val); 24 | } 25 | 26 | // 27 | public Dictionary> CheckRouteData() 28 | { 29 | var result = new Dictionary>(); 30 | HttpRouteValueDictionary defaults = new HttpRouteValueDictionary(); 31 | defaults.Add("controller", "Demo"); 32 | defaults.Add("action", "Get"); 33 | defaults.Add("val", 0); 34 | HttpRouteValueDictionary constraints = new HttpRouteValueDictionary(); 35 | constraints.Add("val", new DoubleRouteConstraint()); 36 | 37 | HttpRoute route = new HttpRoute("cutomer/{controller}/{action}/{val}", defaults, constraints); 38 | var customerRouteData = route.GetRouteData(RequestContext.VirtualPathRoot, Request); 39 | Request.GetRouteData(); 40 | result.Add("CustomerApi", customerRouteData == null ? null : customerRouteData.Values); 41 | var defaultRouteData = RequestContext.RouteData.Route.GetRouteData(RequestContext.VirtualPathRoot, Request); 42 | result.Add("DefaultApi", defaultRouteData == null ? null : defaultRouteData.Values); 43 | return result; 44 | 45 | } 46 | 47 | [HttpGet] 48 | public Dictionary GenerateVirtualPath() 49 | { 50 | Dictionary result = new Dictionary(); 51 | IHttpRoute defaultApi = RequestContext.Configuration.Routes["DefaultApi"]; 52 | IHttpRoute customerApi = RequestContext.Configuration.Routes["CustomerApi"]; 53 | HttpRouteValueDictionary vals = new HttpRouteValueDictionary(); 54 | vals.Add("controller", "Demo"); 55 | vals.Add("action", "Get"); 56 | vals.Add(HttpRoute.HttpRouteKey, true);//可能是必须 57 | var defaultPath = defaultApi.GetVirtualPath(Request, vals); 58 | var customerPath = customerApi.GetVirtualPath(Request, vals); 59 | result.Add("DefaultApi", defaultPath.VirtualPath); 60 | result.Add("CustomerApi", customerPath.VirtualPath); 61 | return result; 62 | } 63 | 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /API_3/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /API_8/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Reflection; 8 | using System.Web.Http; 9 | using System.Web.Http.ExceptionHandling; 10 | using System.Web.Http.ValueProviders; 11 | using System.Web.Http.ValueProviders.Providers; 12 | 13 | namespace API_8.Controllers 14 | { 15 | public class DemoController : ApiController 16 | { 17 | public Dictionary> GetAllMultiServices() 18 | { 19 | Dictionary> result = new Dictionary>(); 20 | FieldInfo field = RequestContext.Configuration.Services.GetType().GetField("_defaultServicesMulti", 21 | BindingFlags.NonPublic|BindingFlags.Instance); 22 | Dictionary> multiServices = (Dictionary>)field.GetValue(RequestContext.Configuration.Services); 23 | foreach (var s in multiServices) 24 | { 25 | List items = new List(); 26 | foreach (var item in s.Value) { 27 | items.Add(item.GetType()); 28 | } 29 | result[s.Key] = items; 30 | } 31 | return result; 32 | } 33 | 34 | public Dictionary GetAllSingleServices() 35 | { 36 | Dictionary result = new Dictionary(); 37 | FieldInfo field = RequestContext.Configuration.Services.GetType().GetField("_defaultServicesSingle", 38 | BindingFlags.NonPublic | BindingFlags.Instance); 39 | Dictionary services = (Dictionary)field.GetValue(RequestContext.Configuration.Services); 40 | foreach (var s in services) 41 | { 42 | 43 | result.Add(s.Key, s.Value==null?null:s.Value.GetType()); 44 | } 45 | return result; 46 | } 47 | 48 | public Dictionary> AddMultiService() 49 | { 50 | List valueProviderFactories=new List(){ 51 | new QueryStringValueProviderFactory(), 52 | new RouteDataValueProviderFactory(), 53 | new MyValueProviderFactory() 54 | }; 55 | RequestContext.Configuration.Services.GetActionInvoker(); 56 | RequestContext.Configuration.Services.ReplaceRange(typeof(ValueProviderFactory), valueProviderFactories); 57 | return GetAllMultiServices(); 58 | } 59 | 60 | public Dictionary ReplaceSingleService() 61 | { 62 | RequestContext.Configuration.Services.Replace(typeof(IExceptionHandler), new MyExceptionHandler()); 63 | return GetAllSingleServices(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /FilterChannelDemo/FilterChannelDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8E4BF6BF-D6DD-4EA6-B6D2-D65420FC3E18} 8 | Exe 9 | Properties 10 | FilterChannelDemo 11 | FilterChannelDemo 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 69 | -------------------------------------------------------------------------------- /API_4/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_6/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_7/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_8/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_9/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_11/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_12/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_13/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /API_3/Models/Clone/ApiController.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Net.Http.Formatting; 8 | using System.Net.Http.Headers; 9 | using System.Text; 10 | using System.Web; 11 | using System.Web.Http.ModelBinding; 12 | using System.Web.Http.Results; 13 | 14 | namespace API_3.Models.Controller 15 | { 16 | public abstract class ApiController 17 | { 18 | /* 19 | protected internal virtual InvalidModelStateResult BadRequest(ModelStateDictionary modelState); 20 | 21 | protected internal virtual NegotiatedContentResult Content(HttpStatusCode statusCode, T value); 22 | 23 | protected internal FormattedContentResult Content(HttpStatusCode statusCode, T value, MediaTypeFormatter formatter); 24 | 25 | protected internal virtual FormattedContentResult Content(HttpStatusCode statusCode, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType); 26 | 27 | protected internal FormattedContentResult Content(HttpStatusCode statusCode, T value, MediaTypeFormatter formatter, string mediaType); 28 | 29 | protected internal CreatedNegotiatedContentResult Created(string location, T content); 30 | 31 | protected internal virtual CreatedNegotiatedContentResult Created(Uri location, T content); 32 | 33 | protected internal virtual CreatedAtRouteNegotiatedContentResult CreatedAtRoute(string routeName, IDictionary routeValues, T content); 34 | 35 | protected internal CreatedAtRouteNegotiatedContentResult CreatedAtRoute(string routeName, object routeValues, T content); 36 | 37 | 38 | 39 | protected internal virtual InternalServerErrorResult InternalServerError(); 40 | 41 | protected internal virtual ExceptionResult InternalServerError(Exception exception); 42 | 43 | protected internal JsonResult Json(T content); 44 | 45 | protected internal JsonResult Json(T content, JsonSerializerSettings serializerSettings); 46 | 47 | protected internal virtual JsonResult Json(T content, JsonSerializerSettings serializerSettings, Encoding encoding); 48 | 49 | protected internal virtual NotFoundResult NotFound(); 50 | 51 | protected internal virtual OkResult Ok(); 52 | 53 | protected internal virtual OkNegotiatedContentResult Ok(T content); 54 | 55 | protected internal virtual RedirectResult Redirect(string location); 56 | 57 | protected internal virtual RedirectResult Redirect(Uri location); 58 | 59 | protected internal virtual RedirectToRouteResult RedirectToRoute(string routeName, IDictionary routeValues); 60 | 61 | protected internal RedirectToRouteResult RedirectToRoute(string routeName, object routeValues); 62 | 63 | protected internal virtual ResponseMessageResult ResponseMessage(HttpResponseMessage response); 64 | 65 | protected internal virtual StatusCodeResult StatusCode(HttpStatusCode status); 66 | 67 | protected internal virtual UnauthorizedResult Unauthorized(IEnumerable challenges); 68 | 69 | protected internal UnauthorizedResult Unauthorized(params AuthenticationHeaderValue[] challenges); 70 | */ 71 | } 72 | } -------------------------------------------------------------------------------- /API_15.Web/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /API_15/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # Roslyn cache directories 20 | *.ide/ 21 | 22 | # MSTest test Results 23 | [Tt]est[Rr]esult*/ 24 | [Bb]uild[Ll]og.* 25 | 26 | #NUNIT 27 | *.VisualState.xml 28 | TestResult.xml 29 | 30 | # Build Results of an ATL Project 31 | [Dd]ebugPS/ 32 | [Rr]eleasePS/ 33 | dlldata.c 34 | 35 | *_i.c 36 | *_p.c 37 | *_i.h 38 | *.ilk 39 | *.meta 40 | *.obj 41 | *.pch 42 | *.pdb 43 | *.pgc 44 | *.pgd 45 | *.rsp 46 | *.sbr 47 | *.tlb 48 | *.tli 49 | *.tlh 50 | *.tmp 51 | *.tmp_proj 52 | *.log 53 | *.vspscc 54 | *.vssscc 55 | .builds 56 | *.pidb 57 | *.svclog 58 | *.scc 59 | 60 | # Chutzpah Test files 61 | _Chutzpah* 62 | 63 | # Visual C++ cache files 64 | ipch/ 65 | *.aps 66 | *.ncb 67 | *.opensdf 68 | *.sdf 69 | *.cachefile 70 | 71 | # Visual Studio profiler 72 | *.psess 73 | *.vsp 74 | *.vspx 75 | 76 | # TFS 2012 Local Workspace 77 | $tf/ 78 | 79 | # Guidance Automation Toolkit 80 | *.gpState 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper*/ 84 | *.[Rr]e[Ss]harper 85 | *.DotSettings.user 86 | 87 | # JustCode is a .NET coding addin-in 88 | .JustCode 89 | 90 | # TeamCity is a build add-in 91 | _TeamCity* 92 | 93 | # DotCover is a Code Coverage Tool 94 | *.dotCover 95 | 96 | # NCrunch 97 | _NCrunch_* 98 | .*crunch*.local.xml 99 | 100 | # MightyMoose 101 | *.mm.* 102 | AutoTest.Net/ 103 | 104 | # Web workbench (sass) 105 | .sass-cache/ 106 | 107 | # Installshield output folder 108 | [Ee]xpress/ 109 | 110 | # DocProject is a documentation generator add-in 111 | DocProject/buildhelp/ 112 | DocProject/Help/*.HxT 113 | DocProject/Help/*.HxC 114 | DocProject/Help/*.hhc 115 | DocProject/Help/*.hhk 116 | DocProject/Help/*.hhp 117 | DocProject/Help/Html2 118 | DocProject/Help/html 119 | 120 | # Click-Once directory 121 | publish/ 122 | 123 | # Publish Web Output 124 | *.[Pp]ublish.xml 125 | *.azurePubxml 126 | ## TODO: Comment the next line if you want to checkin your 127 | ## web deploy settings but do note that will include unencrypted 128 | ## passwords 129 | #*.pubxml 130 | 131 | # NuGet Packages Directory 132 | packages/* 133 | ## TODO: If the tool you use requires repositories.config 134 | ## uncomment the next line 135 | #!packages/repositories.config 136 | 137 | # Enable "build/" folder in the NuGet Packages folder since 138 | # NuGet packages use it for MSBuild targets. 139 | # This line needs to be after the ignore of the build folder 140 | # (and the packages folder if the line above has been uncommented) 141 | !packages/build/ 142 | 143 | # Windows Azure Build Output 144 | csx/ 145 | *.build.csdef 146 | 147 | # Windows Store app package directory 148 | AppPackages/ 149 | 150 | # Others 151 | sql/ 152 | *.Cache 153 | ClientBin/ 154 | [Ss]tyle[Cc]op.* 155 | ~$* 156 | *~ 157 | *.dbmdl 158 | *.dbproj.schemaview 159 | *.pfx 160 | *.publishsettings 161 | node_modules/ 162 | 163 | # RIA/Silverlight projects 164 | Generated_Code/ 165 | 166 | # Backup & report files from converting an old project file 167 | # to a newer Visual Studio version. Backup files are not needed, 168 | # because we have git ;-) 169 | _UpgradeReport_Files/ 170 | Backup*/ 171 | UpgradeLog*.XML 172 | UpgradeLog*.htm 173 | 174 | # SQL Server files 175 | *.mdf 176 | *.ldf 177 | 178 | # Business Intelligence projects 179 | *.rdl.data 180 | *.bim.layout 181 | *.bim_*.settings 182 | 183 | # Microsoft Fakes 184 | FakesAssemblies/ 185 | 186 | # LightSwitch generated files 187 | GeneratedArtifacts/ 188 | _Pvt_Extensions/ 189 | ModelManifest.xml -------------------------------------------------------------------------------- /API_4/Controllers/FigureController.cs: -------------------------------------------------------------------------------- 1 | using API_4.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | using System.Web.Http.ModelBinding; 9 | using System.Web.Http.ValueProviders; 10 | 11 | namespace API_4.Controllers 12 | { 13 | [RoutePrefix("api/Figure")] 14 | public class FigureController : ApiController 15 | { 16 | #region url 17 | public Figure GetFigureFromQueryString(Figure figure) 18 | { 19 | return figure; 20 | } 21 | 22 | public Figure GetFigureFromQueryStringNotAll(Figure figure) 23 | { 24 | return figure; 25 | } 26 | 27 | 28 | [Route("GetFigureFromRoute/{FirstName}/{LastName}")] 29 | public Figure GetFigureFromRoute(Figure figure) 30 | { 31 | return figure; 32 | } 33 | 34 | [Route("GetFigureFromRouteAndQueryString/{FirstName}/{LastName}")] 35 | public Figure GetFigureFromRouteAndQueryString(Figure figure) 36 | { 37 | return figure; 38 | } 39 | 40 | [Route("GetTwoFigureFromRoute/{a.FirstName}/{a.LastName}/{b.FirstName}/{b.LastName}")] 41 | public List GetTwoFigureFromRoute(Figure a, Figure b) 42 | { 43 | List result = new List(); 44 | result.Add(a); 45 | result.Add(b); 46 | return result; 47 | } 48 | 49 | //[Route("GetTwoFigureFromRoute/{a.FirstName}/{a.LastName}/{b.FirstName}/{b.LastName}")] 50 | public List GetTwoFigureFromQueryString(Figure a, Figure b) 51 | { 52 | List result = new List(); 53 | result.Add(a); 54 | result.Add(b); 55 | return result; 56 | } 57 | 58 | public Figure GetComplexFigureFromQueryString(Figure figure) 59 | { 60 | return figure; 61 | 62 | } 63 | 64 | [Route("GetComplexFigureFromRoute/{FirstName}/{LastName}/{Direwolf.Name}/{Direwolf.Color}")] 65 | public Figure GetComplexFigureFromRoute(Figure figure) 66 | { 67 | return figure; 68 | 69 | } 70 | 71 | public List GetTwoComplexFigureFromQueryString(Figure a, Figure b) 72 | { 73 | List result = new List(); 74 | result.Add(a); 75 | result.Add(b); 76 | return result; 77 | 78 | } 79 | 80 | [Route("GetTwoComplexFigureFromRoute/{a.FirstName}/{a.LastName}/{a.Direwolf.Name}/{a.Direwolf.Color}/{b.FirstName}/{b.LastName}/{b.Direwolf.Name}/{b.Direwolf.Color}")] 81 | public List GetTwoComplexFigureFromRoute(Figure a, Figure b) 82 | { 83 | List result = new List(); 84 | result.Add(a); 85 | result.Add(b); 86 | return result; 87 | } 88 | 89 | public List GetList([ModelBinder] List list) 90 | { 91 | return list; 92 | } 93 | 94 | public List GetFigureList([ModelBinder] List list) 95 | { 96 | return list; 97 | } 98 | 99 | public List GetTwoFigureList([ModelBinder] List list1, [ModelBinder] List list2) 100 | { 101 | List list = new List(); 102 | list.AddRange(list1); 103 | list.AddRange(list2); 104 | return list; 105 | } 106 | 107 | 108 | public Dictionary GetDictionary([ModelBinder]Dictionary dic) 109 | { 110 | return dic; 111 | } 112 | #endregion 113 | 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /API_15.Web/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 | 5 | 6 | 7 | 8 | 9 | 10 | Index 11 | 20 | 21 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | First Name 107 | Last Name 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /Model/Model.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4F0F7BB5-B1A8-4FD4-90A5-B2C004918342} 8 | Library 9 | Properties 10 | Model 11 | Model 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | False 35 | ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll 36 | 37 | 38 | 39 | 40 | 41 | False 42 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 43 | 44 | 45 | False 46 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll 47 | 48 | 49 | False 50 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 74 | -------------------------------------------------------------------------------- /API_2/Controllers/FigureController.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web.Http; 8 | 9 | namespace API_2.Controllers 10 | { 11 | public class FigureController : ApiController 12 | { 13 | #region Http方法匹配 14 | public IEnumerable GetAll() 15 | { 16 | return FigureManager.Figures; 17 | } 18 | 19 | public IEnumerable GetPostAll()//只能用GET方法请求 20 | { 21 | return FigureManager.Figures; 22 | } 23 | 24 | [HttpPost] 25 | public IEnumerable Get()//不能用GET方法请求,只能用Post方法请求 26 | { 27 | return FigureManager.Figures; 28 | } 29 | 30 | [AcceptVerbs("POST")] 31 | [HttpPut] 32 | public IEnumerable PostByBody([FromBody] Figure figure)//可以用Put,Post方法请求 33 | { 34 | string body = Request.Content.ReadAsStringAsync().Result; 35 | if (figure != null) 36 | { 37 | FigureManager.Figures.Add(figure); 38 | } 39 | return FigureManager.Figures; 40 | } 41 | #endregion 42 | 43 | #region Action名匹配 44 | public Figure GetFigure(string firstName) 45 | { 46 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName); 47 | return result; 48 | } 49 | #endregion 50 | 51 | #region 所有参数无默认值 52 | public Figure GetFromQueryString(string firstName) 53 | { 54 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName); 55 | return result; 56 | } 57 | public Figure GetFromQueryString(string firstName, string lastName) 58 | { 59 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName && t.LastName == lastName); 60 | return result; 61 | } 62 | 63 | public Figure GetFromQueryStringDefaultValue([FromUri] Figure figure) 64 | { 65 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == figure.FirstName && t.LastName == figure.LastName); 66 | return result; 67 | } 68 | 69 | #endregion 70 | 71 | #region 存在默认只参数 72 | public IEnumerable GetFromQueryStringDefaultValue(string lastName = "Stack") 73 | { 74 | var result = FigureManager.Figures.Where(t => t.LastName == lastName); 75 | return result; 76 | } 77 | public Figure GetFromQueryStringDefaultValue(string firstName, string lastName = "Stack") 78 | { 79 | var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName && t.LastName == lastName); 80 | return result; 81 | } 82 | 83 | //public Figure GetFromQueryStringDefaultValue(string firstName="Bran", string lastName = "Stack") 84 | //{ 85 | // var result = FigureManager.Figures.FirstOrDefault(t => t.FirstName == firstName && t.LastName == lastName); 86 | // return result; 87 | //} 88 | 89 | public int GetFromQueryStringDefaultValue1(string x,string y,string z="z") 90 | { 91 | return 1; 92 | } 93 | public int GetFromQueryStringDefaultValue1(string x, string y) 94 | { 95 | return 2; 96 | } 97 | public int GetFromQueryStringDefaultValue1(string x) 98 | { 99 | return 3; 100 | } 101 | #endregion 102 | 103 | #region 参数类型 104 | public string GetFromQueryStringType(string x, string y) 105 | { 106 | return x + y; 107 | } 108 | public int GetFromQueryStringType(int x, int y) 109 | { 110 | return x + y; 111 | } 112 | 113 | //public void GetFromQueryStringType1(int x, string y) 114 | //{ } 115 | //public void GetFromQueryStringType1(string x, int y) 116 | //{ } 117 | #endregion 118 | 119 | 120 | 121 | } 122 | } 123 | --------------------------------------------------------------------------------