Default Windows Username and Date/Time Stamp

Hi,

I have created a host of lookup tables and brought them into Radzen and its all working really well. I've read a couple of earlier posts but I don't understand how to bring into my project a default windows NT username as a column with a date/time stamp? Once this is populated I would want this to write back into my sql server table like the other values. I'm brand new to radzen and I wondered if you had a mini step-by-step guide for this?

Thanks

Chris

Hi Chris,

If you want to get the current Windows user and date when creating new record you can use partial class with OnXXXCreated() partial method as described in this article:

For example:

    public partial class OrdersController
    {
        partial void OnOrderCreated(Models.Sample.Order item)
        {
            item.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            item.OrderDate = DateTime.UtcNow;
        }
    }

Best Regards,
Vladimir

Thank you for getting back to me so promptly. I'll give your solution a try.

Many thanks

Chris

Hi Chris,

On the other hand this is just the Windows user running the app. If you need full Windows Authentication you can enable it in IIS:

and tell the Radzen app to use it in Startup.cs

  public partial class Startup
  {
    partial void OnConfigureServices(IServiceCollection services)
    {
      services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
    }
  }

In this case the user can be accessed like this:

    public partial class OrdersController
    {
        partial void OnOrderCreated(Models.Sample.Order item)
        {
            item.UserName = User.Identity.Name;
            item.OrderDate = DateTime.UtcNow;
        }
    }