Blazor 5x - قسمت 34 - توزیع برنامههای Blazor بر روی IIS
نویسنده: وحید نصیری
تاریخ: ۱۴۰۰/۰۱/۱۲ ۱۲:۱۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
dotnet publish -o "c:\dir1\dir2" -c Release
<PropertyGroup>
<PublishIISAssets>true</PublishIISAssets>
</PropertyGroup> <SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
<InvariantGlobalization>true</InvariantGlobalization>
function isWasmSupported() {
try {
if (typeof WebAssembly === "object"
&& typeof WebAssembly.instantiate === "function") {
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
if (module instanceof WebAssembly.Module)
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
}
} catch (e) {
}
return false;
}
if(!isWasmSupported()) {
alert("WebAssembly is not available in your browser. Please try using the latest version of Chrome, Firefox, Edge or Safari.");
} [_Host.cshtml]
<script src="_framework/blazor.server.js"></script>
<script>
window.Blazor.defaultReconnectionHandler.onConnectionDown = function () {
setTimeout(function () {
location.reload();
}, 7000);
}
window.Blazor.defaultReconnectionHandler._reconnectCallback = function (d) {
document.location.reload();
}
</script> <!DOCTYPE html> <html> <head> <base href="/" />
<base href="/blazor/" />
<base href="/blazor/" />
<base href="/Blazor/" />
System.ArgumentException: The URI is not contained by the base URI
<script>
var path = window.location.pathname.split('/');
var baseTag = document.getElementsByTagName('base');
baseTag[0].setAttribute('href', '/' + path[1] + '/');
</script> <PublishTrimmed>true</PublishTrimmed> <TrimMode>link</TrimMode>
اما هنگام پابلیش ، تو پوشه _framework هنوز حدود 200 dll قرار میگیره و دانلود اینها تو مرورگر لود را میبره بالا .
| dotnet.wasm | Transfer size (kB) |
|---|---|
| .NET 5 default | 884 |
| .NET 6 default | 780 |
| .NET 6 relinked | 756 |
| .NET 6 invariant mode | 393 |
<head> <base href="/blazortest/" />
Microsoft.AspNetCore.Components.WebAssembly.Server
app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseRouting();
app.MapFallbackToFile("index.html"); name: Deploy to GitHub Pages
# Run workflow on every push to the main branch
on:
push:
branches: [ main ]
jobs:
deploy-to-github-pages:
# use ubuntu-latest image to run steps on
runs-on: ubuntu-latest
steps:
# uses GitHub's checkout action to checkout code form the main branch
- uses: actions/checkout@v2
# sets up .NET Core SDK
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.302
# publishes Blazor project to the release-folder
- name: Publish .NET Core Project
run: dotnet publish ./src/DNTPersianComponents.Blazor.WasmSample/Server/DNTPersianComponents.Blazor.WasmSample.Server.csproj -c Release -o release --nologo
# changes the base-tag in index.html from '/' to 'DNTPersianComponents.Blazor' to match GitHub Pages repository subdirectory
- name: Change base-tag in index.html from / to DNTPersianComponents.Blazor
run: sed -i 's/<base href="\/" \/>/<base href="\/DNTPersianComponents.Blazor\/" \/>/g' release/wwwroot/index.html
# copy index.html to 404.html to serve the same file when a file is not found
- name: copy index.html to 404.html
run: cp release/wwwroot/index.html release/wwwroot/404.html
# add .nojekyll file to tell GitHub pages to not treat this as a Jekyll project. (Allow files and folders starting with an underscore)
- name: Add .nojekyll file
run: touch release/wwwroot/.nojekyll
- name: Commit wwwroot to GitHub Pages
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: github-pages
FOLDER: release/wwwroot src: url('/lib/samim-font/Samim-Bold.eot?v=4.0.5'); src: url('../lib/samim-font/Samim-Bold.eot?v=4.0.5'); dotnet workload install wasm-tools
<PropertyGroup> <RunAOTCompilation>true</RunAOTCompilation> </PropertyGroup>
<PropertyGroup>
<BlazorLinkOnBuild Condition="'$(Configuration)'!='Release'">false</BlazorLinkOnBuild>
</PropertyGroup> crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Arg_NoDefCTor, Wasm.Shared.MainLayout
System.MissingMethodException: Arg_NoDefCTor, Wasm.Shared.MainLayout
at System.RuntimeType.CreateInstanceMono(Boolean , Boolean )
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean , Boolean )
at System.Activator.CreateInstance(Type , Boolean , Boolean )
at System.Activator.CreateInstance(Type , Boolean )
at System.Activator.CreateInstance(Type )
at Microsoft.AspNetCore.Components.DefaultComponentActivator.CreateInstance(Type )
at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider , Type )
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateComponent(Type )
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame& , Int32 )
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& , Int32 )
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& , Int32 )
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& , Int32 )
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& , Int32 , Int32 , Int32 , Int32 )
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer , RenderBatchBuilder , Int32 , ArrayRange`1 , ArrayRange`1 )
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder , RenderFragment , Exception& )
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry )
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue() blazor.webassembly.js:1:38555 <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> <CascadingAuthenticationState>
<Router AppAssembly="typeof(App).Assembly" PreferExactMatches="true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<Authorizing>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Authorizing>
<NotAuthorized>
@* <RedirectToLogin/>*@
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<span>Error</span>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>