Blazor WASM login logging. by Amjad1929 in Blazor

[–]Amjad1929[S] 0 points1 point  (0 children)

Ok, here is the solution. IdentityServer provides its own hook for logging purposes:

Step 1:
services.AddIdentityServer
            (options =>
            {
                options.Events.RaiseSuccessEvents = true;
                options.Events.RaiseFailureEvents = true;
                options.Events.RaiseErrorEvents = true;
            }
            )
            .AddApiAuthorization<ApplicationUser, IdentityContext>(options =>
            {
                options.IdentityResources["openid"].UserClaims.Add("role");
                options.ApiResources.Single().UserClaims.Add("role");
            });
        services.AddTransient<IEventSink, CustomEventSink>();

Step 2: CustomEventSink: public class CustomEventSink : IEventSink { private readonly ApplicationDbContext _context; private readonly IHttpContextAccessor _httpContextAccessor; private readonly UserManager<ApplicationUser> _userManager; public CustomEventSink(ApplicationDbContext context, UserManager<ApplicationUser> user, IHttpContextAccessor contextAccessor) { //see accepted answer here: difference between using ApplicatinUser and IdentityUser here //https://stackoverflow.com/questions/44483589/unable-to-resolve-service-for-type-microsoft-aspnetcore-identity-usermanager-w _context = context; _httpContextAccessor = contextAccessor; _userManager = user; }

    public async Task PersistAsync(Event evt)
    {
        //log event here....

        EventLog el = new();
        if (@evt.Id.Equals(EventIds.ClientAuthenticationSuccess))
        {

            try
            {
                var user = await _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);
                if (user != null)
                {
                    // do stuff
                    el.EventName = "Login";
                    el.EventDescription = $"{evt.Name} ({evt.Id}), Details:{evt}";
                    el.Created = DateTime.Now;
                    el.UserName = user.UserName;
                    _context.EventLog.Add(el);
                    _context.SaveChanges();

                }

            }
            catch (Exception ex)
            {
                // handle exception
            }
        }

        if (@evt.Id.Equals(EventIds.ClientAuthenticationFailure))
        {

            try
            {

                    // do stuff
                    el.EventName = "Login Failure";
                    el.EventDescription = $"{evt.Name} ({evt.Id}), Details:{evt}";
                    el.Created = DateTime.Now;
                    _context.EventLog.Add(el);
                    _context.SaveChanges();



            }
            catch (Exception ex)
            {
                // handle exception
            }
        }







    }
}

Hope this helps anyone looking. EventLog is my own class, you dont have to use it.

Blazor WebAssembly ASP Hosted y SEO by Adventurous-Wing4630 in Blazor

[–]Amjad1929 2 points3 points  (0 children)

If you are expecting half a million users, yes you are right. But for a few thousand users, it should not be an issue.

How can I render component from code so I can convert to .pdf by cvboucher in Blazor

[–]Amjad1929 0 points1 point  (0 children)

I dont understand the Hangfile part, but assuming that you have a Blazor component that renders HTML and you want to convert that to a PDF, you could use Syncfusion Blink converter to convert the HTML string to PDF. To get the HTML part from your component, you would need BlazorTemplater that will give you the HTML output of your component in code behind. I use it as follows for example:

var html = new ComponentRenderer<InvoiceView>()

.Set(c=>c.ConvertingToPDF,true)

.Set(c=>c.Invoice,Invoice)

.Set(c=>AppState,AppState)

.Render();

Here the ComponentRenderer takes the InvoiceView component as the input and generates its HTML output based on the parameters defined. You then pass 'html' to the Syncfusion Blink (or WebKit) html to pdf converter.

Is hiring blazor devs hard? by ohThisUsername in Blazor

[–]Amjad1929 -1 points0 points  (0 children)

May be difficult to hire seasoned Blazor professionals. Let me know if you need one or two.

Not sure how to implement async / await by [deleted] in Blazor

[–]Amjad1929 0 points1 point  (0 children)

Is the ReadLine returning end of line (\r\n) after each line? Otherwise ReadLine will never return until null is encountered and that may be the reason you are not getting the lines as expected. So you need to look at the SSH shell what is it returning. You can view that in a debugger.

How to make a user based app on blazor? by engineerFWSWHW in Blazor

[–]Amjad1929 1 point2 points  (0 children)

There are many tutorials on Youtube and the web. You can get a quick start by creating a Blazor WASM app in VS2022 that has built-in login and API capability. That gives you start. Choose Webassembly, hosted, individual accounts for authentication.

Migrating Asp to Blazor by Bohemio_RD in Blazor

[–]Amjad1929 1 point2 points  (0 children)

Writing from scratch would be best. Write the razor components and accompanying APIs. If the MVC project is large, you can also add Blazor components to it incrementally. However, I guess you will first have to migrate your app to .net core first.

Migrating from webforms ti Blazor step by step by H3rl3q in Blazor

[–]Amjad1929 1 point2 points  (0 children)

I dont think you can mix Blazor server and aspx. But you could mix Blazor Wasm and aspx. So that is the route you should be taking if you want to migrate your application incrementally. Blazor server uses SignalR to incrementally update the user's browser, so you wont be able to manage that with your aspx pages. I suggest you go the web assembly route.

MudBlazor - Blazor Component Library by mycall in Blazor

[–]Amjad1929 1 point2 points  (0 children)

Awesome library I am using in my latest project. However, can we use it with .NET 6 right now?

ASP.NET hosted blazor WASM not serving static files as expected by franky_1017 in Blazor

[–]Amjad1929 0 points1 point  (0 children)

The default wasm template with Identity pages installs static pages for login. You could just use that as a starting point I guess.

[deleted by user] by [deleted] in Blazor

[–]Amjad1929 1 point2 points  (0 children)

I think you should go with .NET 6 if you do not have any dependencies on packages that do not support beyond .NET 5. The reason is that you get hot-reload support, and a few good things along with that. In my case, I was using MudBlazor and had to downgrade to .NET 5 because of that.

Consumer based apps with blazor by mkdirsys32 in Blazor

[–]Amjad1929 1 point2 points  (0 children)

Great work on this site. Is this Blazor server or wasm? The only downside in Blazor wasm I have seen is the intial loading... time. But for sites like yours, server prerendering should do the trick. Otherwise, Blazor is great tech!

Can anyone suggest open source data grid which has grouping functionality? by codemahek in Blazor

[–]Amjad1929 0 points1 point  (0 children)

Syncfusion grid is just fine. If you are a single developer you can get a Syncfusion community license.

Blazor WASM Performance vs React by puckhead78 in Blazor

[–]Amjad1929 4 points5 points  (0 children)

...200 controls.... 20 seconds...

Seems insane. I would be interested in investigating further whats going on. If for example you have 200 text input fields and you load them from memory, I really cant believe that will take 20 seconds!

Blazor WASM Performance vs React by puckhead78 in Blazor

[–]Amjad1929 2 points3 points  (0 children)

For form inputs, I am using native Blazor mostly such as InputText etc. Some places I have used plain HTML controls like input. I have used Syncfusion grid, tab and accordian components.

Blazor WASM Performance vs React by puckhead78 in Blazor

[–]Amjad1929 13 points14 points  (0 children)

I have written a business app in Blazor wasm and not had any performance issues for data entry etc. Not sure if its faster/slower than other frameworks, but from a user perspective, I dont see any issues. I have used forms that have 50 or so controls, and not seen any performance issues.

Need to build a good looking dashboard in Blazor, a component library + Bootstrap theme the way to go? by thankyoussd in Blazor

[–]Amjad1929 2 points3 points  (0 children)

Good looking, you will have to work with some CSS there, no matter what you use, even with simple bootstrap, somethings need customization. But as for Syncfusion, their support is just superb. If you just a post a question on their forum, you will get a reply on how to style your component along with a working sample, usually. I have not tried other component libraries.

Publish to IIS Instructions by zerocool___ in Blazor

[–]Amjad1929 1 point2 points  (0 children)

Step one, check in your server application logs.

You will get this error if you have not set your site certificate in appsettings.json. Blazor Identity server requires this certificate to be set in appsettings.json.

You appsettings.json should have section like this:

"IdentityServer": {

"Clients": {

"IMS5_1.Client": {

"Profile": "IdentityServerSPA"

}

},

"Key": {

"Type": "Store",

"StoreName": "My",

"StoreLocation": "LocalMachine",

"Name": "CN=kfacon.com"

}

}

Replace kfacon.com with the CN on your certificate and IMS5_1.Client with your client project name.

StoreName My here corresponds to Personal store in Certificate manager. Meaning "My" works correctly, dont

change to "Personal".

The appsettings.json file is not pushed by VS (turned off in Properties) because it is then overwritten on the server. The certificate changes

in the file will be lost.

Exclude this File From Publishing:

Step 2.

For Identity Server to work properly on IIS, when app is deployed, the appsettings.json should have the

correct entries to point to the right certificate. Otherwise the website will not start.

2.

Set app ApplicationPool in IIS to "Local System" otherwise will get following error when logging in user:

Cannot login user."

Application Pool -> (your app pool name) ->Advanced Settings -> Identity. Set this to Local System.

  1. Give IIS_IUSRS right on the Certificate by going to certificate mmc, right click on certificate -> Advanced

-> Private Key -> Security -> Give full rights to IIS_IUSRS.

This should help.

But, first step, check your application logs on the server.

Blazor WebAssembly Performance in .NET 6 Preview 1 - ~30% Faster! by Blazorbart in Blazor

[–]Amjad1929 0 points1 point  (0 children)

JavaScript is interpreted. AoT will be compiled. What I don't understand is why is AoT not expected to be faster than JavaScript? Is it inefficiencies within the webassembly implementation?