diff --git a/App_Start/BundleConfig.cs b/App_Start/BundleConfig.cs deleted file mode 100644 index 13718c4..0000000 --- a/App_Start/BundleConfig.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Optimization; - -public class BundleConfig -{ - public static void RegisterBundles(BundleCollection bundles) - { - // Bundle JavaScript files. - bundles.Add(new ScriptBundle("~/bundles/scripts") - .Include("~/node_modules/jquery/dist/jquery.min.js") - .Include("~/node_modules/angular/angular.min.js") - .IncludeDirectory("~/WebApp", "*.js", false) - .IncludeDirectory("~/WebApp/Components", "*.js", true) - .IncludeDirectory("~/WebApp/Directives", "*.js", true)); - - // Bundles CSS files - bundles.Add(new StyleBundle("~/bundles/styles") - .IncludeDirectory("~/Content", "*.css", true) - .IncludeDirectory("~/WebApp", "*.css", true)); - } -} diff --git a/App_Start/RouteConfig.cs b/App_Start/RouteConfig.cs deleted file mode 100644 index 336e299..0000000 --- a/App_Start/RouteConfig.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; -using System.Web.Routing; - -namespace asp_net_angularjs -{ - public class RouteConfig - { - public static void RegisterRoutes(RouteCollection routes) - { - routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); - - routes.MapRoute( - name: "Landing", - url: "", - defaults: new { controller = "Landing", action = "Index", id = UrlParameter.Optional } - ); - } - } -} diff --git a/Controllers/LandingController.cs b/Controllers/LandingController.cs index 2888a1c..1b19413 100644 --- a/Controllers/LandingController.cs +++ b/Controllers/LandingController.cs @@ -1,16 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; +using Microsoft.AspNetCore.Mvc; namespace asp_net_angularjs.Controllers { - public class LandingController : Controller - { - public ActionResult Index() + [ApiController] + [Route("api/[controller]")] + public class LandingController : ControllerBase { - return View(); + [HttpGet] + public IActionResult Get() + { + return Ok(new { message = "ASP.NET Core 7 Web API is running", timestamp = DateTime.UtcNow }); + } + + [HttpGet("health")] + public IActionResult Health() + { + return Ok(new { status = "healthy", service = "angularjs-aspnetcore-webapi" }); + } } - } } diff --git a/Global.asax b/Global.asax deleted file mode 100644 index 5a72af9..0000000 --- a/Global.asax +++ /dev/null @@ -1 +0,0 @@ -<%@ Application Codebehind="Global.asax.cs" Inherits="asp_net_angularjs.MvcApplication" Language="C#" %> diff --git a/Global.asax.cs b/Global.asax.cs deleted file mode 100644 index 4d07a6e..0000000 --- a/Global.asax.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Web.Mvc; -using System.Web.Routing; -using System.Web.Optimization; - -namespace asp_net_angularjs -{ - public class MvcApplication : System.Web.HttpApplication - { - protected void Application_Start() - { - AreaRegistration.RegisterAllAreas(); - RouteConfig.RegisterRoutes(RouteTable.Routes); - BundleConfig.RegisterBundles(BundleTable.Bundles); - } - } -} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..69a69ae --- /dev/null +++ b/Program.cs @@ -0,0 +1,48 @@ +using Microsoft.Extensions.FileProviders; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowAngularJS", policy => + { + policy.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader(); + }); +}); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseCors("AllowAngularJS"); + +app.UseStaticFiles(); + +app.UseStaticFiles(new StaticFileOptions +{ + FileProvider = new PhysicalFileProvider( + Path.Combine(builder.Environment.ContentRootPath, "node_modules")), + RequestPath = "/node_modules" +}); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.MapFallbackToFile("index.html"); + +app.Run(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..12f750e --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:51267", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7000;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Views/Landing/Index.cshtml b/Views/Landing/Index.cshtml deleted file mode 100644 index 92d72ed..0000000 --- a/Views/Landing/Index.cshtml +++ /dev/null @@ -1,26 +0,0 @@ - -@using System.Web.Optimization -@{ - Layout = null; -} - - - - - - - - - XLTS for AngularJS with .NET Framework - - - - @Styles.Render("~/bundles/styles") - @Scripts.Render("~/bundles/scripts") - - -

XLTS for AngularJS with .NET Framework

- - - - diff --git a/Views/web.config b/Views/web.config deleted file mode 100644 index 4502e7d..0000000 --- a/Views/web.config +++ /dev/null @@ -1,42 +0,0 @@ - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/angularjs-aspnetcore-webapi.csproj b/angularjs-aspnetcore-webapi.csproj new file mode 100644 index 0000000..742145e --- /dev/null +++ b/angularjs-aspnetcore-webapi.csproj @@ -0,0 +1,25 @@ + + + + net8.0 + enable + enable + asp_net_angularjs + asp-net-angularjs + false + + + + + + + + + + + + + + + + diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css new file mode 100644 index 0000000..e21633a --- /dev/null +++ b/wwwroot/css/site.css @@ -0,0 +1,4 @@ +body { + font-family: 'Roboto', sans-serif; + padding: 20px; +} diff --git a/wwwroot/index.html b/wwwroot/index.html new file mode 100644 index 0000000..fd64df6 --- /dev/null +++ b/wwwroot/index.html @@ -0,0 +1,27 @@ + + + + + + + + XLTS for AngularJS with ASP.NET Core + + + + + + + + +

XLTS for AngularJS with ASP.NET Core

+ + + + + + + + + + diff --git a/wwwroot/js/Components/test.component.css b/wwwroot/js/Components/test.component.css new file mode 100644 index 0000000..47ff154 --- /dev/null +++ b/wwwroot/js/Components/test.component.css @@ -0,0 +1,5 @@ +.test-component { + color: #1565c0; + font-size: x-large; + font-weight: bold; +} diff --git a/wwwroot/js/Components/test.component.js b/wwwroot/js/Components/test.component.js new file mode 100644 index 0000000..0913c56 --- /dev/null +++ b/wwwroot/js/Components/test.component.js @@ -0,0 +1,17 @@ +angular.module('app').component('testComponent', { + controllerAs: 'vm', + controller: TestComponent, + template: '
AngularJS Version: {{vm.version}}
', + bindings: {}, +}); + +TestComponent.$inject = ['$log']; + +function TestComponent($log) { + var vm = this; + vm.version = angular.version.full; + + vm.$onInit = function () { + $log.info('test-component initialized...'); + }; +} diff --git a/wwwroot/js/Directives/test.directive.css b/wwwroot/js/Directives/test.directive.css new file mode 100644 index 0000000..0c5a4d7 --- /dev/null +++ b/wwwroot/js/Directives/test.directive.css @@ -0,0 +1,5 @@ +.test-directive { + color: #2196f3; + font-size: large; + font-weight: bold; +} diff --git a/wwwroot/js/Directives/test.directive.html b/wwwroot/js/Directives/test.directive.html new file mode 100644 index 0000000..8b7ad43 --- /dev/null +++ b/wwwroot/js/Directives/test.directive.html @@ -0,0 +1 @@ +
jQuery Version: {{ vm.version }}
diff --git a/wwwroot/js/Directives/test.directive.js b/wwwroot/js/Directives/test.directive.js new file mode 100644 index 0000000..3d8500f --- /dev/null +++ b/wwwroot/js/Directives/test.directive.js @@ -0,0 +1,17 @@ +angular.module('app').directive('testDirective', TestDirective); + +TestDirective.$inject = ['$log']; + +function TestDirective($log) { + return { + restrict: 'E', + scope: {}, + templateUrl: '/js/Directives/test.directive.html', + controllerAs: 'vm', + controller: function () { + var vm = this; + vm.version = $().jquery; + $log.info('test-directive initialized...'); + }, + }; +} diff --git a/wwwroot/js/app.js b/wwwroot/js/app.js new file mode 100644 index 0000000..a74216b --- /dev/null +++ b/wwwroot/js/app.js @@ -0,0 +1 @@ +angular.module('app', []);