„IAppBuilder“ enthält keine Definition für „UseOpenIdConnectAuthentication“.C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 „IAppBuilder“ enthält keine Definition für „UseOpenIdConnectAuthentication“.

Post by Anonymous »

Ich versuche, Entra Active Directory in meiner ASP.NET MVC-Anwendung zu implementieren. Zuvor verwendete die App die OWIN-Authentifizierung, um sich beim System anzumelden.
Die App läuft auf .NET Framework 4.8.
Das gilt auch für die Entra-Anmeldung Ich habe die NuGet-Pakete auf die neueste Version aktualisiert und einige zusätzliche Pakete hinzugefügt.

Code: Select all

Microsoft.Owin -Version 4.2.2
Microsoft.Owin.Host.SystemWeb -Version 4.2.2
Microsoft.Owin.Security -Version 4.2.2
Microsoft.Owin.Security.Cookies -Version 4.2.2
Microsoft.Owin.Security.OpenIdConnect -Version 4.2.2
Microsoft.IdentityModel.Protocols.OpenIdConnect -Version 8.3.0
Microsoft.IdentityModel.Tokens -Version 8.3.0
Als nächstes habe ich die Startup.Auth.cs-Klasse aktualisiert:

Code: Select all

using System;
using System.Configuration;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.Google;
using Owin;
using TorquexMediaPlayer.Models;

namespace TorquexMediaPlayer
{
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// These values can be stored in Web.config or appSettings.json
string clientId = ConfigurationManager.AppSettings["ClientId"];
string clientSecret = ConfigurationManager.AppSettings["ClientSecret"];
string tenantId = ConfigurationManager.AppSettings["TenantId"];
// e.g., "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or "mytenant.onmicrosoft.com"

// Authority format: "https://login.microsoftonline.com/{tenantId}/v2.0"
string authority = $"https://login.microsoftonline.com/{tenantId}/v2.0";

// CookieAuthentication must be enabled for OWIN to store user information after sign-in
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());

// Configure the OpenIdConnect middleware
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
RedirectUri = "https://localhost:44300/signin-oidc",
PostLogoutRedirectUri = "https://localhost:44300/",
Scope = OpenIdConnectScope.OpenIdProfile,
ResponseType = OpenIdConnectResponseType.CodeIdToken,

// Use the client secret to authenticate your app
ClientSecret = clientSecret,

// Token validation parameters
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
// For single-tenant apps, validate the issuer to be your specific tenant
ValidIssuer = $"https://login.microsoftonline.com/{tenantId}/v2.0"
},

// Notification handlers
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
// Handle authentication failures
context.HandleResponse();
context.Response.Redirect("/Error?message="  + context.Exception.Message);
return System.Threading.Tasks.Task.FromResult(0);
}
}
});
}
}
Aber wenn ich alle Pakete zur Klasse hinzufüge, bekomme ich diese Fehler

'IAppBuilder' enthält keine Definition für „UseOpenIdConnectAuthentication“ und keine zugängliche Erweiterungsmethode „UseOpenIdConnectAuthentication“, die ein erstes Argument vom Typ „IAppBuilder“ akzeptiert, konnte gefunden werden (fehlt Ihnen eine using-Direktive oder eine Assembly-Referenz?)


Der Typ- oder Namespacename „OpenIdConnectAuthenticationOptions“ konnte nicht gefunden werden (fehlt Ihnen eine using-Direktive oder ein Assemblyverweis?)

Der Typ- oder Namespacename „OpenIdConnectAuthenticationNotifications“ konnte nicht gefunden werden (fehlt Ihnen eine using-Direktive oder ein Assemblyverweis?)

Ich habe versucht, alle zugehörigen Pakete zu deinstallieren und neu zu installieren, aber das Problem besteht weiterhin.
Ich habe auch versucht, die Pakete herunterzustufen , aber das Problem besteht weiterhin.
Wie kann dieses Problem gelöst werden?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post