asp.net NET核心,在Macbook上找不到localhost

fcwjkofz  于 2022-11-19  发布在  .NET
关注(0)|答案(1)|浏览(309)

我有一个奇怪的问题,我的ASP.NET核心应用程序。当我运行在本地端口从我的MacBook,项目正在建设,但在浏览器中,我只看到这个错误。
找不到此localhost页面找不到此网址的网页:HTTP错误404您访问的页面不存在
我的问题是,问题是从哪里发生的,原因是什么?如果你没事,我会附上我的github repo来检查代码。https://github.com/ddxkalin/MovieDatabase

gojuced7

gojuced71#

总结:
您当前的问题404是由于注解掉路由模板而导致的。但是如果您使用路由模板,您将遇到一个新的问题,即找不到方法,因为您的Web项目是.net core3.1,它使用带有包Microsoft.AspNetCore.Identity 3.1.0SigninManager,而您的Services项目是.netstandard 2.0,它将SigninManagerMicrosoft.AspNetCore.Identity 2.2.0一起使用。这将导致找不到该方法。两个不同版本的包使用两个不同的SigninManager构造函数。Microsoft.AspNetCore.Identity 2.2.0中的登录管理器:

public class SignInManager<TUser> where TUser : class
{ 
    public SignInManager(UserManager<TUser> userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory<TUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor, ILogger<SignInManager<TUser>> logger, IAuthenticationSchemeProvider schemes);

Microsoft.AspNetCore.Identity 3.1.0中的登录管理器:

public class SignInManager<TUser> where TUser : class
{ 
    public SignInManager(UserManager<TUser> userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory<TUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor, ILogger<SignInManager<TUser>> logger, IAuthenticationSchemeProvider schemes,
                                      IUserConfirmation<TUser> confirmation);

MovieDatabase.Web项目中,您应该使用下面的路线模板:

app.UseEndpoints(endpoint =>
{
    endpoint.MapControllerRoute("admin", "{area:exists}/{controller=Dashboard}/{action=Index}/{id?}");
    endpoint.MapControllerRoute(name: "default", "{controller=Home}/{action=Index}/{id?}");
    endpoint.MapRazorPages();
});

MovieDatabase.Services项目中,更改您的项目文件和ApplicationSignInManager.cs如下:
1.将TargetFramework更改为netcoreapp3.1,并将Microsoft.AspNetCore.AppFrameworkReference相加:

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
 
  <FrameworkReference Include="Microsoft.AspNetCore.App" />

  <PackageReference Include="RestSharp" Version="106.6.2" />
  <PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta009" PrivateAssets="all">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
  </PackageReference>
</ItemGroup>

2:将ApplicationSignInManager.cs

public class ApplicationSignInManager<TUser> : SignInManager<ApplicationUser>
    where TUser : ApplicationUser
{
    public ApplicationSignInManager(
        ApplicationUserManager<ApplicationUser> userManager,
        IHttpContextAccessor contextAccessor,
        IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory,
        IOptions<IdentityOptions> optionsAccessor,
        ILogger<SignInManager<ApplicationUser>> logger,
        IAuthenticationSchemeProvider schemeProvider,
        IUserConfirmation<ApplicationUser> userConfirmation       //add this...
    )
    : base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemeProvider, userConfirmation)
    {
    }

相关问题