Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to Setup Windows Authentication for ASP.Net Core with .Net Platform.

$
0
0

   A VS2017 ASP.Net Core MVC project targeting the .Net Framework platform was created.  I then want to use filter attribute [Authorize(Roles=WorkerFunction1")] to control who can access what functionality in the application.

 

  I am getting No authenticationScheme was specified and there was no DefaultChallengeScheme found when I an action with Authorize filter is called.

  Assuming I need something in the startup cs. 

  I am following below and not sure if I am in right place as I want to target platform as .Net Framework for Windows authentication with IIS.

https://docs.microsoft.com/en-us/aspnet/core/security/authorization/limitingidentitybyscheme?tabs=aspnetcore2x

   So attempting to update startup.cs the IService Collection does not contain a definition for AddAuthorization ..

                  // using Microsoft.AspNetCore.Server.IISIntegration;
            services.AddAuthentication(IISDefaults.AuthenticationScheme);

    Any help getting to documentation for using ASP.Net Core with .Net Framework as platform and using roles in Windows or what I am doing incorrectly would be helpful.

code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Server.IISIntegration;

namespace WebApplication7
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();          
            //Below for using http.sys as asp.net core not compatible with Windows authentication
            //  services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);
           services.AddAuthorization();
      

            // using Microsoft.AspNetCore.Server.IISIntegration;
            services.AddAuthentication(IISDefaults.AuthenticationScheme);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>