diff --git a/.gitignore b/.gitignore index 69e715c..68a7db5 100644 --- a/.gitignore +++ b/.gitignore @@ -370,3 +370,6 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd + +# ASP.NET Core specific +appsettings.Development.json 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/HealthController.cs b/Controllers/HealthController.cs new file mode 100644 index 0000000..fbadb22 --- /dev/null +++ b/Controllers/HealthController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; + +namespace AngularJS.AspNetCore.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class HealthController : ControllerBase + { + [HttpGet] + public IActionResult Get() + { + return Ok(new + { + status = "healthy", + timestamp = DateTime.UtcNow, + version = "1.0.0", + framework = ".NET 7.0" + }); + } + } +} diff --git a/Controllers/LandingController.cs b/Controllers/LandingController.cs deleted file mode 100644 index 2888a1c..0000000 --- a/Controllers/LandingController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; - -namespace asp_net_angularjs.Controllers -{ - public class LandingController : Controller - { - public ActionResult Index() - { - return View(); - } - } -} 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..09a4355 --- /dev/null +++ b/Program.cs @@ -0,0 +1,44 @@ +using System.IO; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Hosting; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +var fileProvider = new PhysicalFileProvider( + Path.Combine(Directory.GetCurrentDirectory())); + +var defaultFilesOptions = new DefaultFilesOptions +{ + FileProvider = fileProvider, + RequestPath = "" +}; +defaultFilesOptions.DefaultFileNames.Clear(); +defaultFilesOptions.DefaultFileNames.Add("index.html"); +app.UseDefaultFiles(defaultFilesOptions); + +var staticFileOptions = new StaticFileOptions +{ + FileProvider = fileProvider, + RequestPath = "" +}; +app.UseStaticFiles(staticFileOptions); + +app.UseRouting(); +app.MapControllers(); +app.MapFallbackToFile("index.html"); + +app.Run(); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index bf6d758..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("asp_net_angularjs")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("asp_net_angularjs")] -[assembly: AssemblyCopyright("Copyright © 2022")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("43046e18-f0d2-4443-98d5-4650bdcb3a8b")] - -// Version information for an assembly consists of the following four values: -// Major Version -// Minor Version -// Build Number -// Revision - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/README.md b/README.md index aec5e26..3d3dd9b 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,41 @@ -# AngularJS with .NET Framework -A demo project using AngularJS, .NET Framework 4.8, and ASP.NET MVC 5. +# AngularJS with ASP.NET Core 7 + +A demo project using AngularJS and ASP.NET Core 7 Web API. ## Features - XLTS for AngularJS - installed using npm - jQuery 3.6.3 - installed using npm -- .NET Framework 4.8 -- ASP.NET MVC 5 -- Bundling using [Microsoft.AspNet.Web.Optimization](https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification) +- ASP.NET Core 7 Web API +- Static file serving for AngularJS SPA ## Prerequisites -- Windows 10/11 - Older versions of Windows may work but have not been tested. -- [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) - The free *Community Edition* is sufficient. -Older versions of Visual Studio may work but have not been tested. -- [.Net Framework 4.8](https://dotnet.microsoft.com/en-us/download/dotnet-framework) - This can optionally be installed -as part of the Visual Studio 2022 installation as well. +- [.NET 7.0 SDK](https://dotnet.microsoft.com/download/dotnet/7.0) +- [Node.js 18+](https://nodejs.org/) with npm 9+ ## Getting Started -- Make sure you have configured your authentication with the XLTS.dev registry by supplying your token in the `.npmrc` file in your user home directory. - > **Note** - > If you don't have a token for the XLTS.dev registry, you can use the LTS AngularJS packages - see the next section. +1. Make sure you have configured your authentication with the XLTS.dev registry by supplying your token in the `.npmrc` file in your user home directory. + + > **Note** + > If you don't have a token for the XLTS.dev registry, you can use the LTS AngularJS packages - see the next section. -- Clone repository: `git clone https://github.com/xlts-dev/angularjs-asp-net48-mvc5.git`. -- Switch to the project's directory: `cd angularjs-asp-net48-mvc5`. -- Install npm packages: `npm install`. -- Open the project in Visual Studio. -- Run the project by pressing the `F5` key or using the green start button in the toolbar. This will launch your web - browser and display the web application. +2. Clone repository: `git clone https://github.com/COG-GTM/angularjs-asp-net48-mvc5.git` +3. Switch to the project's directory: `cd angularjs-asp-net48-mvc5` +4. Install npm packages: `npm install` +5. Run the application: `dotnet run --project angularjs-aspnetcore7.csproj` +6. Open your browser and navigate to the URL shown in the console (typically `http://localhost:5000` or `https://localhost:5001`) ## AngularJS LTS packages -If you want to use the LTS packages, you have to run `npm run switch-to-lts-packages` script instead of `npm install`. + +If you want to use the LTS packages, run `npm run switch-to-lts-packages` script instead of `npm install`. + +## API Endpoints + +The application includes a sample API endpoint: +- `GET /api/health` - Returns application health status + +## Development + +To view the Swagger UI for API documentation, navigate to `/swagger` when running in development mode. 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; -} - - - - -
- - - -