Discussion on Blazor, a framework for building web apps with .NET and WebAssembly https://blazor.net
dotnet-maestro[bot] on darc-master-a926ae60-afdc-46d8-aabc-bb225655c15e
dotnet-maestro[bot] on master
Update dependencies from https:… (compare)
dotnet-maestro[bot] on darc-master-a926ae60-afdc-46d8-aabc-bb225655c15e
Update dependencies from https:… (compare)
dotnet-maestro[bot] on darc-master-a926ae60-afdc-46d8-aabc-bb225655c15e
dotnet-maestro[bot] on darc-master-e3474f54-f92f-4c3f-b116-ed9bdfe9754d
I've got my file download things working. Blazor sends a request to an authorized API to be able to download a file and gets back a token (that the API uses to know which file to build. You then download the file with the following TS:
export function downloadFile(fileUri): void {
let anchorElement = document.createElement('a');
anchorElement.download = "true";
anchorElement.href = fileUri;
anchorElement.click();
anchorElement.remove();
}
@SQL-MisterMagoo you mentioned to add the target="_blank"
attribute to the download link. This causes a new browser tab to appear ever so briefly. Turns out there's a download
attribute to use instead.
@optimizasean I think I found a way to get your navigationmanager based policy to work - maybe, but only by using RequireAssertion.
Your comment about NavigationManager being "stuck" was, I think, slightly off - it's the RequireClaim that gets "stuck" - it is only evaluated at startup, so only returns resource Ids for the base url (or whatever url you first load)
RequireAssertion uses a Func that is called every time the policy is checked, so in there you can happily reference the current URL and check the claims.
This was just a quick test to see if it works - and it does - not saying that checking claims that way is correct, just "does it work as an idea"
Program.cs
NavigationManager navMan = default;
builder.Services.AddAuthorizationCore(options =>
{
options.AddPolicy(Policies.CanAccessResource, builder=>Policies.CanAccessResourcePolicy(builder,navMan));
});
var app = builder.Build();
navMan = app.Services.GetRequiredService<NavigationManager>();
await app.RunAsync();
Policies.cs
public static AuthorizationPolicy CanAccessResourcePolicy(AuthorizationPolicyBuilder builder, NavigationManager navMan)
=> builder.RequireAssertion(context => {
var resourceIds = GetResourceValues(new List<int>() { 2, 3, 5, 6 }, navMan);
return context.User.HasClaim(claim =>
claim.Type == "ResourceName" && resourceIds.Contains(claim.Value)
);
}).Build();
does anybody made .Net 6 Preview 6 MAUI Blazor Template working (just plain project, then hit F5 and run)? Preview 5 worked well, preview 6 does not start (WinUI Project not startable, publish file not startable. Edge Web View 2 installed)
Funny, i could never got it to work in Preview 5 but it works for me in Preview 6. You are using VS 2022, right?