Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows authentication in asp.net 5

I am building an intranet application in ASP .NET 5, MVC 6. I want to know how to enable Windows Authentication.? The default project template supports only Individual User Accounts.

like image 926
AnandhaSundari M Avatar asked Feb 16 '15 13:02

AnandhaSundari M


People also ask

How do I use Windows Authentication in .NET Core API?

For . Start Visual Studio and select Create a new project. In the Create a new project dialog, select ASP.NET Core Web App (or Web API) > Next. In the Configure your new project dialog, enter Project name > Next. In the Additional Information dialog, select Authentication Type as Windows.

How do we implement Windows Authentication?

On the taskbar, click Start, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off. Expand Internet Information Services, then World Wide Web Services, then Security. Select Windows Authentication, and then click OK.

How do I enable Windows Authentication in Visual Studio?

Right-click the project in Solution Explorer and select Properties. Select the Debug tab. Clear the checkbox for Enable Anonymous Authentication. Select the checkbox for Enable Windows Authentication.

How does Windows Authentication work in C#?

Basic AuthenticationAfter a user provides built-in Windows user account information, the data is transmitted to the web server. Once IIS receives the authentication data, it attempts to authenticate the user with the corresponding Windows account. This password is encoded using Base64 and sent to the server.


Video Answer


1 Answers

Mark's answer is still valid in ASP.Net RC1. There are some additional steps to tie it all together (I don't have enough reputation to comment on his solution):

  1. Install WebListener from NuGet
  2. Add the following usings to Startcup.cs:

    using Microsoft.AspNet.Http.Features;
    using Microsoft.Net.Http.Server;
    
  3. Add Mark's code snippet in the Configure method before app.UseMvc:

    // If we're self-hosting, enable integrated authentication (if we're using
    // IIS, this will be done at the IIS configuration level).
    var listener = app.ServerFeatures.Get<WebListener>();
    if (listener != null)
    {
        listener.AuthenticationManager.AuthenticationSchemes = 
        AuthenticationSchemes.NTLM;
    }
    
  4. To debug this, you need to add the WebListener run target in project.json, as Mark noted in a different answer:

    "commands": {
      "weblistener": "Microsoft.AspNet.Server.WebListener --config hosting.ini",
      "web": "Microsoft.AspNet.Server.Kestrel"
    },
    
  5. Pick weblistener instead of IIS Express of web (Kestrel) to debug your application.

like image 106
zemien Avatar answered Oct 20 '22 16:10

zemien