ASP.NET MVC/Web API project built on .NET Framework 4.8.1 with Vite and Tailwind CSS 4.2 for frontend bundling. This template keeps the classic ASP.NET project structure while using modern utility-first frontend tooling for JS/CSS builds.
- .NET Framework 4.8.1
- ASP.NET MVC 5 + ASP.NET Web API 2
- Vite (frontend bundler)
- NuGet (
packages.config) + Node package manager (NPM) - CSS: Tailwind CSS 4.2
- Icons: Lucide
ASP.NET Web Application with Vite (.NET Framework).csproj- Main project fileControllers/- MVC controllersApp_Start/- Route, Web API, and MVC configurationFilters/- ASP.NET filters (CSP headers)Helpers/- Helper classesMiddleware/- Vite helper middlewareScripts/app.js- JavaScript entry sourceStyles/app.css- Tailwind + custom CSS entry sourceViews/- Razor viewsWeb.config- ASP.NET application configurationvite.config.mjs- Vite build/dev configurationpackage.json- Frontend dependencies and scriptspackages.config- NuGet dependencies
Vite is configured to build assets into:
wwwroot/dist
The Vite config points to:
Scripts/app.js(script entry)Styles/app.css(style entry)
- Visual Studio 2019/2022 with ASP.NET workload
- .NET Framework 4.8.1 SDK installed
- Node.js 20.19+ (or 22.12+; Vite 8 ESM-only runtime requirement)
- npm (or your preferred package manager) running on a supported Node runtime
nuget restore "ASP.NET Web Application with Vite (.NET Framework).csproj"or restore inside Visual Studio (right-click project > Restore NuGet Packages).
npm installnpm run buildOpen the project in Visual Studio and run with IIS Express.
You can run Vite dev server separately when needed:
npm run devThis project uses a global action filter to emit a nonce-based Content-Security-Policy header.
Filters/ContentSecurityPolicyFilter.cs- Generates a random nonce in
OnActionExecuting - Stores it in
HttpContext.Items[NonceKey] - Uses the nonce in
OnResultExecutingto emitscript-srcandstyle-src - Adds Vite exception sources when dev mode is enabled
- Reads Vite dev-mode settings from config and writes to:
CSP_EXTRA_SCRIPT_SRCCSP_EXTRA_STYLE_SRCCSP_EXTRA_CONNECT_SRC
- Generates a random nonce in
- Registered globally in
App_Start/FilterConfig.cs - Applied via
Global.asax.csthroughFilterConfig.RegisterGlobalFilters(GlobalFilters.Filters) Helpers/NonceHelper.csexposes@Html.CspNonce()for Razor views
Views/Shared/_Layout.cshtml applies the nonce to the inline theme script.
Helpers/ViteHelper.cs focuses on rendering <script> and <link> tags.
CSP + Vite dev-server behavior is controlled through Web.config app settings:
UseViteDevServer(true/false)ViteDevServerOrigin(for example:http://localhost:5173)ViteDistPath(for production build output, defaulting towwwroot/dist)
npm run dev- start Vite dev server onlocalhost:5173npm run build- build production assets intowwwroot/distnpm run preview- preview Vite output
node_modules,bin,obj,.vs, andwwwroot/distare ignored in.gitignoreto keep tracked files source-focused.- This project uses
packages.configand classic ASP.NET project style. - Theme and mobile menu icons are rendered through
lucidewith Tailwind class swaps (dark:block,hidden).
- This template keeps
$safeprojectname$as the tokenized namespace/assembly value for template instantiation. - Frontend legacy browser bundles were removed:
bootstrapjQueryjQuery.ValidationMicrosoft.jQuery.Unobtrusive.ValidationModernizr
- Previously removed during cleanup:
Microsoft.AspNet.Web.OptimizationWebGreaseAntlr/Antlr3.Runtime
Microsoft.Web.Infrastructureis intentionally kept because MVC/WebPages pre-start initialization requires it.
- This template favors a Vite-first front-end flow and keeps the jQuery unobtrusive validation stack out by default.
- Practical effect:
- Data annotations still enforce validation on the server (
ModelStateon postback). - Client-side annotation-based validation is not enabled automatically from
Html.*For(...)helpers. - Forms with a legacy MVC UX expectation (
data-val-*auto-wired byjquery.validate) need a replacement path.
- Data annotations still enforce validation on the server (
- If you want the traditional MVC unobtrusive behavior:
- Re-add
jQuery,jQuery.Validation, andMicrosoft.jQuery.Unobtrusive.Validation. - Keep/restore
ClientValidationEnabledandUnobtrusiveJavaScriptEnabledin config. - Include the required JS scripts in your layout (
jquery,jquery.validate,jquery.validate.unobtrusive).
- Re-add
- Modern alternative for this template:
- Keep server-side validation as the source of truth and add targeted client validation via your preferred Vite-managed JS.
- Use existing model constraints to generate server validation messages while validating critical UX paths in custom JS modules.
This project is provided as-is for learning/template purposes.