diff --git a/OwinWebApiTest/App_Start/WebApiConfig.cs b/OwinWebApiTest/App_Start/WebApiConfig.cs index 65200ab..3fc7061 100644 --- a/OwinWebApiTest/App_Start/WebApiConfig.cs +++ b/OwinWebApiTest/App_Start/WebApiConfig.cs @@ -7,7 +7,7 @@ namespace OwinWebApiTest { public static class WebApiConfig { - public static void Register(HttpConfiguration config) + public static HttpConfiguration Register(HttpConfiguration config) { // Web API configuration and services @@ -19,6 +19,8 @@ namespace OwinWebApiTest routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); + + return config; } } } diff --git a/OwinWebApiTest/Controllers/ItemsController.cs b/OwinWebApiTest/Controllers/ItemsController.cs new file mode 100644 index 0000000..e072c8c --- /dev/null +++ b/OwinWebApiTest/Controllers/ItemsController.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; + +using OwinWebApiTest.Models; + +namespace OwinWebApiTest.Controllers +{ + public class ItemsController : ApiController + { + Item[] items = new Item[] + { + new Item { id = 1, name = "Tomato Soup", type = "Groceries" }, + new Item { id = 2, name = "Yo-yo", type = "Toys" }, + new Item { id = 3, name = "Hammer", type = "Hardware" } + }; + + public IEnumerable GetAllItems() + { + return items; + } + + [Authorize] + public IHttpActionResult GetItem(int id) + { + var item = items.FirstOrDefault((i) => i.id == id); + if (item == null) { + return NotFound(); + } + return Ok(item); + } + } +} diff --git a/OwinWebApiTest/Global.asax.cs b/OwinWebApiTest/Global.asax.cs index e1e8b43..0f13cfe 100644 --- a/OwinWebApiTest/Global.asax.cs +++ b/OwinWebApiTest/Global.asax.cs @@ -11,7 +11,7 @@ namespace OwinWebApiTest { protected void Application_Start() { - GlobalConfiguration.Configure(WebApiConfig.Register); + //GlobalConfiguration.Configure(WebApiConfig.Register); } } } diff --git a/OwinWebApiTest/Models/Item.cs b/OwinWebApiTest/Models/Item.cs new file mode 100644 index 0000000..344624d --- /dev/null +++ b/OwinWebApiTest/Models/Item.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace OwinWebApiTest.Models +{ + public class Item + { + public int id { get; set; } + public string name { get; set; } + public string type { get; set; } + } +} \ No newline at end of file diff --git a/OwinWebApiTest/OwinWebApiTest.csproj b/OwinWebApiTest/OwinWebApiTest.csproj index 9232bc5..b16b24c 100644 --- a/OwinWebApiTest/OwinWebApiTest.csproj +++ b/OwinWebApiTest/OwinWebApiTest.csproj @@ -1,7 +1,7 @@  - - + + Debug @@ -43,12 +43,68 @@ 4 - - ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + True + + + ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll + True + + + ..\packages\Microsoft.AspNet.Identity.EntityFramework.2.2.1\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll + True + + + ..\packages\Microsoft.AspNet.Identity.Owin.2.2.1\lib\net45\Microsoft.AspNet.Identity.Owin.dll + True + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll True + + ..\packages\Microsoft.Owin.3.1.0\lib\net45\Microsoft.Owin.dll + True + + + ..\packages\Microsoft.Owin.Cors.3.1.0\lib\net45\Microsoft.Owin.Cors.dll + True + + + ..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + True + + + ..\packages\Microsoft.Owin.Security.3.1.0\lib\net45\Microsoft.Owin.Security.dll + True + + + ..\packages\Microsoft.Owin.Security.Cookies.3.1.0\lib\net45\Microsoft.Owin.Security.Cookies.dll + True + + + ..\packages\Microsoft.Owin.Security.OAuth.3.1.0\lib\net45\Microsoft.Owin.Security.OAuth.dll + True + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + + + ..\packages\Microsoft.AspNet.Cors.5.2.3\lib\net45\System.Web.Cors.dll + True + @@ -58,6 +114,10 @@ + + ..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll + True + @@ -67,9 +127,6 @@ - - ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll @@ -86,10 +143,14 @@ + Global.asax + + + @@ -102,8 +163,6 @@ - - 10.0 @@ -134,8 +193,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + + + +
+ - - + + - - - - + + + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + \ No newline at end of file diff --git a/OwinWebApiTest/packages.config b/OwinWebApiTest/packages.config index 4dc8b2f..e21f221 100644 --- a/OwinWebApiTest/packages.config +++ b/OwinWebApiTest/packages.config @@ -1,10 +1,23 @@  + + + + + + - - - + + + + + + + + + + \ No newline at end of file