小编Jah*_*han的帖子

部署 Web 应用程序期间出现错误“无法打开源文件:找不到路径的一部分”

我在部署网络应用程序期间遇到错误。错误的标题是Could not open Source file: Could not find a part of the path

'无法打开源文件:找不到路径的一部分'E:\ARCHIVES\Projects\Main\Jahan.Handicraft\Jahan.Handicraft.Web.Mvc.UmbracoCms.App\obj\Release\AspnetCompileMerge\TempBuildDir\App_Plugins \UmbracoForms\Data\Web.config;\App_Plugins\UmbracoForms\Data\Web.config'.'。

我在我的项目中使用了Umbraco 7.4.3und ASP.NET MVC。我想将其部署在本地主机上。

我怎么解决这个问题?错误图片

deployment asp.net-mvc umbraco web-deployment umbraco7

4
推荐指数
1
解决办法
4565
查看次数

从ASP.NET Identity 2.x中的角色中删除用户

如何从ASP.NET Identity 2.x中的角色中删除用户?关于向用户添加角色没有问题,但是当我想从用户中删除角色时我无法解决.应该提到的是没有异常或错误!

//POST: Admin/User/Edit/5
    [AcceptVerbs(HttpVerbs.Post)]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Edit([Bind(Prefix = "")]UserViewModel userViewModel, List<int> availableRoles)
    {
        if (ModelState.IsValid)
        {
            List<int> newListOfRolesIDs = availableRoles;
            List<int> oldListOfRolesIDs = UserBLL.Instance.GetRolesIDs(userViewModel.Id);
            List<int> deletedList;
            List<int> addedList;
            var haschanged = oldListOfRolesIDs.ChangeTracking(newListOfRolesIDs, out deletedList, out addedList);
            using (new EFUnitOfWorkFactory().Create())
            {
                if (haschanged)
                {
                    UserBLL.Instance.InsertRoles(addedList, userViewModel.Id);
                    UserBLL.Instance.DeleteRoles(deletedList, userViewModel.Id);
                }
                await UserBLL.Instance.UpdateAsync(userViewModel);
            }
            //ArticleBLL.Instance.UpdatePartial(articleViewModel,  m => m.Title);
            return RedirectToAction("Edit");
        }
        return View(userViewModel);
    }
Run Code Online (Sandbox Code Playgroud)

删除角色方法:

public void DeleteRoles(List<int> deleteList, int? userId)
    {
        if (userId != null)
        {
            User user …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-identity asp.net-identity-2

3
推荐指数
1
解决办法
1万
查看次数

在类“Program”上调用方法“BuildWebHost”时出错

当我运行时 dotnet ef migrations add Initial_Identity,出现此错误:

在类“Program”上调用方法“BuildWebHost”时出错。在没有应用程序服务提供商的情况下继续。错误:GenericArguments 1 , 'Microsoft.AspNetCore.Identity.IdentityRole', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim]'s 违反了'TRole' 类型的约束。脚手架操作可能会导致数据丢失。请检查迁移的准确性。

我该如何解决?

这是我的代码:

创业班

public void ConfigureServices(IServiceCollection services)
{
    // some codes
    services.AddIdentity<User, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
}
Run Code Online (Sandbox Code Playgroud)

程序类

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseDefaultServiceProvider(options => options.ValidateScopes = false)
            .Build();
}
Run Code Online (Sandbox Code Playgroud)

TemporaryDbContextFactory 类

public class TemporaryDbContextFactory : 
IDesignTimeDbContextFactory<ApplicationDbContext>
{
    //////// 
    public ApplicationDbContext CreateDbContext(string[] args)
    {
        var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
        IConfigurationRoot …
Run Code Online (Sandbox Code Playgroud)

asp.net entity-framework-core asp.net-core-2.0 ef-core-2.0 entity-framework-migrations

3
推荐指数
1
解决办法
2160
查看次数

在 ASP.NET Core 2 中的 layout.cshtml 中使用和路由 Less 文件

我在我的项目中使用了管理部分的模板(引导管理模板),并从中安装了它Bower,我已经应用了ASP.NET Core 2.

当我运行项目时,我收到一个错误:

FileError: ' http://localhost:52125/lib/bootstrap-admin-template/public/assets/less/theme.less ' 未找到 (404)

在 theme.less

但是文件 ,theme.less存在于路径中!!我不知道为什么浏览器无法识别该文件。

为了路由theme.less我所做的文件:

<link rel="stylesheet/less" type="text/css" href="~/lib/bootstrap-admin-template/public/assets/less/theme.less">
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

错误

theme.less 文件路径

文件和文件夹的树状结构

html asp.net less razor asp.net-core

3
推荐指数
1
解决办法
1143
查看次数

在 ViewComponent 中:此异步方法缺少“await”运算符,并且将同步运行

在 ViewComponent 中我收到此警告:(我已经使用过ASP.NET Core 2

警告 CS1998:此异步方法缺少“等待”运算符,并将同步运行。考虑使用“await”运算符等待非阻塞 API 调用,或使用“await Task.Run(...)”在后台线程上执行 CPU 密集型工作。

我该如何解决?

public class GenericReportViewComponent : ViewComponent
{
   public GenericReportViewComponent()
   {
   }
   public async Task<IViewComponentResult> InvokeAsync(GenericReportViewModel model)
   {
       return View(model);
   }
}
Run Code Online (Sandbox Code Playgroud)

更新:

鉴于,我有@await

 <div class="container">
        @await Component.InvokeAsync("GenericReport", new GenericReportViewModel() { })
    </div>
Run Code Online (Sandbox Code Playgroud)

c# asp.net async-await asp.net-core asp.net-core-2.0

3
推荐指数
1
解决办法
2103
查看次数

当使用 Angular 路由守卫时: 'Observable&lt;true | undefined&gt;' 不可分配给类型 &gt; 'Observable&lt;boolean&gt;'

我是角度新手。

我怎么解决这个问题?

我已经安装了 AngularCLI: 11.0.7和 Node:12.18.4

我已经安装了 Angular 路线防护:

ng g guard auth --skip-tests
Run Code Online (Sandbox Code Playgroud)

错误:

错误:src/app/_guards/auth.guard.ts:15:5 - 错误 TS2322:类型 'Observable<true | undefined>' 不可分配给类型'Observable'。输入“布尔值|” undefined' 不可分配给类型'boolean'。类型“未定义”不可分配给类型“布尔”。

 15     return this.accountService.currentUser$.pipe(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 16       map(user => {
    ~~~~~~~~~~~~~~~~~~~
...
 19       })
    ~~~~~~~~
 20     )
    ~~~~~
src/app/_guards/auth.guard.ts:16:11 - error TS7030: Not all code paths return a value.

16       map(user => {
             ~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

警卫

代码:

import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
import { ToastrService } …
Run Code Online (Sandbox Code Playgroud)

angular angular-router-guards angular-guards

3
推荐指数
1
解决办法
1186
查看次数

如何从已创建的 jwt.verify() 方法的结果中获取属性

在我的 Node.js 项目中,我使用了 TypeScript。

我想得到userId结果,jwt.verify()但我得到了一个错误。

我该如何解决这个问题?(如果我不使用 typescript,就没有问题。)

userService.ts 文件:

在登录方法中我有以下代码:

import jwt from "jsonwebtoken"; 

// I have defined userId
token = jwt.sign({ userId: userId, email: email }, secretKey, { expiresIn: expiresIn });
Run Code Online (Sandbox Code Playgroud)

检查 auth.ts 文件:

另外在 check-auth 中间件中我有:

 import jwt from "jsonwebtoken";


 const decodedToken = jwt.verify(token, process.env.SECRET_KEY);

 // Property 'userId' does not exist on type 'string | object'.
 // Property 'userId' does not exist on type 'string'.ts(2339)

 req.userData = { userId: decodedToken.userId }; // I need …
Run Code Online (Sandbox Code Playgroud)

node.js express jwt typescript

3
推荐指数
1
解决办法
4412
查看次数

在ASP.NET MVC中将模型创建为单独的项目

如您所知,ASP.NET MVC中的同一项目中有模型,视图和控制器.但我想从其他人那里获得单独的模型,并在一个单独的项目中创建我的模型(如ClassLibrary项目或任何可能的项目).

我该怎么做?

(我使用EF6和ASP.MVC 4,5和Visual Studio 2013)

c# asp.net-mvc

2
推荐指数
1
解决办法
3949
查看次数

ASP.NET Core 3:无法从根提供程序解析范围服务“Microsoft.AspNetCore.Identity.UserManager`1[Alpha.Models.Identity.User]”

运行项目时,遇到这个问题:(我用过asp.net core 3。)

无法从根提供程序解析范围服务“Microsoft.AspNetCore.Identity.UserManager`1[Alpha.Models.Identity.User]”。

我怎么解决这个问题?

ApplicationDbContext 类:

public class ApplicationDbContext : IdentityDbContext<User, Role, int, 
UserClaim, UserRole, UserLogin, RoleClaim, UserToken>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    {

    }
public static async Task CreateAdminAccount(IServiceProvider 
serviceProvider, IConfiguration configuration)
    {
        UserManager<User> userManager = 
serviceProvider.GetRequiredService<UserManager<User>>();
        RoleManager<Role> roleManager = 
serviceProvider.GetRequiredService<RoleManager<Role>>();

        string userName = configuration["Data:AdminUser:Name"];
        string email = configuration["Data:AdminUser:Email"];
        string password = configuration["Data:AdminUser:Password"];
        string role = configuration["Data:AdminUser:Role"];

        if (await userManager.FindByNameAsync(userName) == null)
        {
            if (await roleManager.FindByNameAsync(role) == null)
            {
                await roleManager.CreateAsync(new Role(role));
            }

            User user …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core asp.net-core-identity asp.net-core-3.0

2
推荐指数
1
解决办法
5255
查看次数

从asp.net core 3.1中的App.config文件中获取数据

我在作为类库项目的项目之一中安装了System.Configuration.ConfigurationManager -Version 4.7.0,然后在其中添加了 app.config 文件。

我在我的项目中应用了 ASP.NET Core 3.1。

现在我想获得部分的价值。

为此,我是这样做的:

namespace Alpha.Infrastructure.PaginationUtility
{
   public class PagingInfo
   {
       public virtual int DefaultItemsPerPage { get; set; } = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DefaultItemsPerPage"]);
   }
}
Run Code Online (Sandbox Code Playgroud)

但是我收到了“ ArgumentNullException: Value cannot be null ”错误!

我怎么解决这个问题?

App.config 文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="DefaultItemsPerPage" value="3"/>
  </appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

c# configurationmanager asp.net-core asp.net-core-3.1

2
推荐指数
1
解决办法
8793
查看次数