«IAppBuilder» не содержит определения «UseOpenIdConnectAuthentication».C#

Место общения программистов C#
Ответить
Anonymous
 «IAppBuilder» не содержит определения «UseOpenIdConnectAuthentication».

Сообщение Anonymous »

Я пытаюсь реализовать Entra Active Directory в своем приложении ASP.NET MVC. Раньше приложение использовало аутентификацию OWIN для входа в систему.
Приложение работает на .NET Framework 4.8.
Так что для входа в систему Entra Я обновил пакеты NuGet до последней версии и добавил несколько дополнительных пакетов.

Код: Выделить всё

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
Далее я обновил класс Startup.Auth.cs:

Код: Выделить всё

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);
}
}
});
}
}
Но когда я добавляю все пакеты в класс, я получаю эти ошибки.

IAppBuilder не содержит определения для «UseOpenIdConnectAuthentication», и не удалось найти доступный метод расширения «UseOpenIdConnectAuthentication», принимающий первый аргумент типа «IAppBuilder» (вам не хватает директивы using или ссылки на сборку?)


Не удалось найти тип или имя пространства имен OpenIdConnectAuthenticationOptions (вам не хватает директивы using или ссылки на сборку?)

Не удалось найти тип или имя пространства имен «OpenIdConnectAuthenticationNotifications» (возможно, вам не хватает директивы using или сборки ссылка?)

Я пытался удалить все связанные пакеты и переустановить их, но проблема не устранена.
Я также пытался понизить версию пакетов, но проблема не устранена.
Как решить эту проблему?

Подробнее здесь: https://stackoverflow.com/questions/793 ... entication
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»