Hello,
I’m trying Wisej 4 beta and looking forward to move projects over from Wisej 3.x .NET framework to Wisej 4 .NET Core 9.
Out of the box, if I create a new project from the WisejWebDesktopApplication template. What are the steps I need to take, running in the debugger, to get Windows Authentication to work in the IE browser that start when I run the program?
In .NET framework I could in properties for the project enable enable “Windows Authentication” and disable “Anonymous Authentication”.
Also in Web.Config I had this:
<system.web> <customErrors mode="Off" /> <authorization> <deny users="?" /> </authorization>
This is the code I have so far, in .NET Core 9 that I think I need. Please correct me if this is not what I need:
Startup.cs:
using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using System; using Wisej.Core; using Microsoft.AspNetCore.Authentication.Negotiate; // Add this namespace for NegotiateDefaults var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args, WebRootPath = "./" }); MGRegnskapWisej.Configure.ConfigureForWisej(); // 1) Register the Negotiate handler builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme) .AddNegotiate(); // 2) Add authorization if you need [Authorize] attributes builder.Services.AddAuthorization(); builder.Services.AddHttpContextAccessor(); var app = builder.Build(); // 3) Plug authentication/authorization into the pipeline app.UseAuthentication(); app.UseAuthorization(); // Add Wisej. app.UseWisej(); // Add FileServer middleware to serve content files excluding .json files. app.UseWhen( context => !context.Request.Path.Value.EndsWith(".json", StringComparison.InvariantCulture), app => app.UseFileServer()); app.Run();
Program.cs:
using System; using System.Collections.Specialized; using System.Diagnostics; using Wisej.Web; namespace MGRegnskapWisej { internal static class Program { /// <summary> /// The main entry point for the application. /// </summary> /// <param name="args">Arguments from the URL.</param> static void Main(NameValueCollection args) { Debug.Print(Application.User.Identity.Name); string s = Application.User.Identity.Name; // <--- I get null on this line Application.Desktop = new MyDesktop(); Window1 window = new Window1(); window.Show(); } } }
So far this is not working. Application.User.Identity.Name is null. There must be additional configuration steps I need to make somewhere to get this working.
Thanks.
Best regards
Wilfred