Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor WebAssembly 7 app in ASP.NET Framework 4.8 project #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ obj/
.idea/
.vs/
*.user
/OldAspNetApp_4_8/_framework/*
12 changes: 12 additions & 0 deletions BlazorWasmApp_7_0/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
19 changes: 19 additions & 0 deletions BlazorWasmApp_7_0/BlazorWasmApp_7_0.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
</ItemGroup>

<Target Name="CopyToSite" AfterTargets="Build" Condition="'$(Configuration)' == 'Debug' ">
<Exec Command="xcopy $(TargetDir)wwwroot\_framework $(SolutionDir)OldAspNetApp_4_8\_framework\ /Y /S" />
<Exec Command="xcopy $(TargetDir)web.config $(SolutionDir)OldAspNetApp_4_8\_framework\ /Y" />
</Target>

</Project>
5 changes: 5 additions & 0 deletions BlazorWasmApp_7_0/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@inherits LayoutComponentBase

<main>
@Body
</main>
20 changes: 20 additions & 0 deletions BlazorWasmApp_7_0/Pages/About.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@page "/Home/About"

<div class="card text-white bg-primary">
<div class="card-header">
Blazor WASM app
</div>
<div class="card-body">
<p>Current count: @currentCount</p>
<button class="btn btn-dark" @onclick="IncrementCount">Click me</button>
</div>
</div>

@code {
int currentCount = 0;

void IncrementCount()
{
currentCount++;
}
}
20 changes: 20 additions & 0 deletions BlazorWasmApp_7_0/Pages/Contact.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@page "/Home/Contact"

<div class="card text-white bg-warning">
<div class="card-header">
Blazor WASM app
</div>
<div class="card-body">
<p>Current count: @currentCount</p>
<button class="btn btn-dark" @onclick="IncrementCount">Click me</button>
</div>
</div>

@code {
int currentCount = 0;

void IncrementCount()
{
currentCount++;
}
}
20 changes: 20 additions & 0 deletions BlazorWasmApp_7_0/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@page "/"

<div class="card text-white bg-success">
<div class="card-header">
Blazor WASM app
</div>
<div class="card-body">
<p>Current count: @currentCount</p>
<button class="btn btn-dark" @onclick="IncrementCount">Click me</button>
</div>
</div>

@code {
int currentCount = 0;

void IncrementCount()
{
currentCount++;
}
}
18 changes: 18 additions & 0 deletions BlazorWasmApp_7_0/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using BlazorWasmApp_7_0;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("BlazorWasmApp");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<INavigationInterception>(new DisabledNavigationInterception());

await builder.Build().RunAsync();

public class DisabledNavigationInterception : INavigationInterception
{
public Task EnableNavigationInterceptionAsync() => Task.CompletedTask;
}
28 changes: 28 additions & 0 deletions BlazorWasmApp_7_0/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"iisExpress": {
"applicationUrl": "http://localhost:11903",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5208",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
7 changes: 7 additions & 0 deletions BlazorWasmApp_7_0/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using BlazorWasmApp_7_0
38 changes: 38 additions & 0 deletions BlazorWasmApp_7_0/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<configuration>
<system.webServer>
<handlers>
<clear />
<add
name="StaticFile"
path="*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
</handlers>
<staticContent>
<remove fileExtension=".blat" />
<remove fileExtension=".dat" />
<remove fileExtension=".dll" />
<remove fileExtension=".br" />
<remove fileExtension=".json" />
<remove fileExtension=".wasm" />
<remove fileExtension=".pdb" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
<mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
<mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
<mimeMap fileExtension=".br" mimeType="application/octet-stream" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".wasm" mimeType="application/wasm" />
<mimeMap fileExtension=".pdb" mimeType="text/plain" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
32 changes: 32 additions & 0 deletions BlazorWasmApp_7_0/wwwroot/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
h1:focus {
outline: none;
}

#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}

.blazor-error-boundary {
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ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EuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
padding: 1rem 1rem 1rem 3.7rem;
color: white;
}

.blazor-error-boundary::after {
content: "An error has occurred."
}
27 changes: 27 additions & 0 deletions BlazorWasmApp_7_0/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<title>BlazorWasmApp_7_0</title>
<base href="/" />
<link href="css/app.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" />

<!-- If you add any scoped CSS files, uncomment the following to load them
<link href="BlazorWasmApp_7_0.styles.css" rel="stylesheet" /> -->
</head>

<body>
<div class="container body-content">
<BlazorWasmApp>Loading...</BlazorWasmApp>
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
</body>

</html>
6 changes: 6 additions & 0 deletions Gaev.BlazorOnAspNet_4_8.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OldAspNetApp_4_8", "OldAspNetApp_4_8\OldAspNetApp_4_8.csproj", "{AAABE4E0-DDA4-48C7-B2AF-9E4F2FEC3353}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWasmApp_7_0", "BlazorWasmApp_7_0\BlazorWasmApp_7_0.csproj", "{8812441E-C18E-4F9F-9762-2ACAEB21F21F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{AAABE4E0-DDA4-48C7-B2AF-9E4F2FEC3353}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAABE4E0-DDA4-48C7-B2AF-9E4F2FEC3353}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAABE4E0-DDA4-48C7-B2AF-9E4F2FEC3353}.Release|Any CPU.Build.0 = Release|Any CPU
{8812441E-C18E-4F9F-9762-2ACAEB21F21F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8812441E-C18E-4F9F-9762-2ACAEB21F21F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8812441E-C18E-4F9F-9762-2ACAEB21F21F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8812441E-C18E-4F9F-9762-2ACAEB21F21F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions OldAspNetApp_4_8/OldAspNetApp_4_8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<Content Include="Scripts\jquery.validate.unobtrusive.js" />
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
<Content Include="Scripts\modernizr-2.8.3.js" />
<Content Include="Views\Shared\BlazorWasmApp.cshtml" />
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
Expand Down
3 changes: 3 additions & 0 deletions OldAspNetApp_4_8/Views/Home/About.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@{
ViewBag.Title = "About";
}

@Html.Partial("BlazorWasmApp")

<main aria-labelledby="title">
<h2 id="title">@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
Expand Down
3 changes: 3 additions & 0 deletions OldAspNetApp_4_8/Views/Home/Contact.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@{
ViewBag.Title = "Contact";
}

@Html.Partial("BlazorWasmApp")

<main aria-labelledby="title">
<h2 id="title">@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
Expand Down
2 changes: 2 additions & 0 deletions OldAspNetApp_4_8/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ViewBag.Title = "Home Page";
}

@Html.Partial("BlazorWasmApp")

<main>
<section class="row" aria-labelledby="aspnetTitle">
<h1 id="title">ASP.NET</h1>
Expand Down
3 changes: 3 additions & 0 deletions OldAspNetApp_4_8/Views/Shared/BlazorWasmApp.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<BlazorWasmApp>Blazor WASM app loading...</BlazorWasmApp>
<base href="/"/>
<script src="/_framework/blazor.webassembly.js"></script>