在 Nestjs 项目中,我遇到了一个库的问题,我没有在代码中直接使用它,但它被第三方使用。
node_modules\wrap-ansi\index.js:2 中的 stringWidth = require('string-width') 不支持
这是 package.json 依赖项:
"dependencies": {
"@nestjs-modules/mailer": "^1.9.1",
"@nestjs/common": "^10.1.2",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^10.1.2",
"@nestjs/event-emitter": "^2.0.2",
"@nestjs/jwt": "^10.0.3",
"@nestjs/mapped-types": "^2.0.2",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.1.2",
"@nestjs/swagger": "^7.1.4",
"@nestjs/throttler": "^4.0.0",
"@nestjs/typeorm": "^10.0.0",
"@ttshivers/automapper-classes": "^8.8.3",
"@ttshivers/automapper-core": "^8.8.3",
"@ttshivers/automapper-nestjs": "^8.8.3",
"bcrypt": "^5.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"handlebars": "^4.7.8",
"nodemailer": "^6.9.7",
"passport": "^0.6.0",
"passport-custom": "^1.1.1",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pg": "^8.11.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"typeorm": "^0.3.16"
},
"devDependencies": {
"@nestjs/cli": "^10.1.11",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.1.2",
"@types/bcrypt": …
Run Code Online (Sandbox Code Playgroud) 我在ASP.NET Core项目的appSettings.json中添加了一个CustomSettings部分键:
{
"ConnectionStrings": {
"DefaultConnectionString": "Data Source=..."
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"CustomSettings": {
"Culture": "es-CO"
}
}
Run Code Online (Sandbox Code Playgroud)
我无法在以下控制器中加载Culture键:
public AccountController(
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
IEmailSender emailSender,
ILogger<AccountController> logger,
IConfiguration configuration)
{
Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(configuration.GetSection("CustomSettings")["Culture"])),
new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
);
}
Run Code Online (Sandbox Code Playgroud)
无论我是否遵循,总是返回NULL:configuration.GetSection("CustomSettings")["Culture"]; configuration.GetSection( "CustomSettings")的GetValue( "文化").
我尝试了基于ASP.NET Core的帮助:在Web项目和类库中访问appsettings.json的分步指南,我创建了具有字符串Culture属性的CustomSettings类,并在Startup中注入如下:
// Load Custom Configuration from AppSettings.json
services.Configure<Models.CustomSettings>(Configuration.GetSection("CustomSettings"));
Run Code Online (Sandbox Code Playgroud)
通过注入IOptions customSettings访问,customSettings.Value.Culture的值返回NULL.
第一个问题:¿我做错了什么或缺少什么?
第二个问题:¿为什么在HomeController的索引中执行以下操作会引发异常?
public class HomeController : Controller
{
public …
Run Code Online (Sandbox Code Playgroud) 在使用 RestAPI 的 ASP.NET Core 5 项目中,我使用带有令牌和刷新令牌的 JWT Bearer。我这样配置启动:
var jwtSecretKey = Configuration.GetValue<string>("Jwt:Key");
var key = Encoding.UTF8.GetBytes(jwtSecretKey);
var tokenValidationParameters = new TokenValidationParameters
{
SaveSigninToken = true,
ValidateActor = true,
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(key),
// set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
ClockSkew = TimeSpan.Zero
};
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme …
Run Code Online (Sandbox Code Playgroud) 在我公司中,我们有一个用C#开发的Windows服务,用于使用SSLStream和Tls12以及服务器和客户端证书来处理来自客户端的请求消息。该服务在Windows Server 2012(包括Windows 10 PC)上都运行良好,无论是以发布模式执行还是调试以检查代码,但是最近执行AuthenticateAsServer时会引发异常。一段代码是:
ServicePointManager.SecurityProtocol = SslProtocols.Tls12;
SslStream secureClient = new SslStream(networkStream, false);
secureClient.AuthenticateAsServer(serverCertificate);
Run Code Online (Sandbox Code Playgroud)
networkStream是具有服务的IP和端口的NetworkStream的实例。serverCertificate是X509Certificate2,它以自签名的方式安装在本地计算机存储中。客户端具有相同的证书。异常详细信息如下:
System.Security.Authentication.AuthenticationException
HResult=-2146233087
Message=A call to SSPI failed, see inner exception.
Source=System
StackTrace:
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at …
Run Code Online (Sandbox Code Playgroud) 最近,我使用个人身份验证启动了Asp.Net Core 2.0 MVC项目。ConfigureServices如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DBConnection")));
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,退出后User.Identity.IsAuthenticated和_signInManager.IsSignedIn(User)仍然为true,无论我是否这样做:await _signInManager.SignOutAsync();
或by await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
并且无论我是否关闭并稍后在浏览器中重新打开应用程序。
我总是需要这样做,如果有人返回索引应用程序或关闭并在浏览器中重新打开该应用程序,则系统会退出以前打开的任何会话并强制登录。
我尝试执行以下操作,但未成功!
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> Login()
{
var auth = User.Identity.IsAuthenticated; // Still true
if (_signInManager.IsSignedIn(User)) // Still true
{
await _signInManager.SignOutAsync();
//HttpContext = new DefaultHttpContext
//{
// User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "username") }, ""))
//};
}
else
{
// Clear the existing external cookie to ensure a clean …
Run Code Online (Sandbox Code Playgroud) c# asp.net asp.net-mvc claims-based-identity asp.net-core-2.0
我正在开发一个 asp.net mvc 项目,我正在使用一个 html 模板来生成一个带有动态数据的发票文档,这些数据是我通过车把填充的。html 结果正在使用 iText 7 转换为 PDF,因为这是公司使用所需的工具,但是我在将其转换为 PDF 时遇到问题,因为有时会显示数据的 html 表格有足够的数据可以容纳在一页中,但在其他情况下,有许多行会形成分页符,从而在两页上打印数据。每当数据不适合一页时,我需要将整个表块移动到下一页。
\n这是模板(Mytemplate.html):
\n<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <title></title>\n <meta name="viewport" content="width=device-width, initial-scale=1">\n <style type="text/css">\n <!-- Removed inline styles for space reasons -->\n </style>\n</head>\n<body>\n<div style="width: 100%; margin: 0 auto; text-align: center; display: flex; justify-content: center;">\n <div style="max-width: 700px; background-color: white; width: 100%">\n <table style="width:100%">\n <tbody>\n <tr>\n <td>\n <table class="table-header table-information m-0 border-zero">\n <tr>\n <td class="text-al" style="vertical-align: top">\n <img src="{{baseUrl}}\\images\\clear_purple.png" style="width: 150px; height: 50px;">\n </td>\n …
Run Code Online (Sandbox Code Playgroud)我遇到了 ASP.NET Core 6 Web 应用程序的问题,该应用程序具有多个项目,其中一些项目由于要求而具有视图和控制器,因此我将它们标记为 as<Project Sdk="Microsoft.NET.Sdk.Razor">
并在启动中添加了应用程序部分,如下所示:
由于我运行 Scaffolding 命令行来构建基于 SQL Server 数据库的实体类,同时为了创建迁移文件,我使用一种技术在创建实体时在设计时对实体进行单数/复数化。为了实现这一目标,我必须通过创建DesignTimeDbContextFactory、DesignTimeServices和Pluralizer类来使用Microsoft.EntityFrameworkCore.Design提供的 DesignTime 服务来提供数据库连接和复数服务,因此我将 Microsoft.EntityFrameworkCore.Design 包添加到主项目和后端(dbcontext 存储库)项目。
为了避免将此包复制到输出发布文件夹(此包不应成为生产的一部分),根据找到的互联网文档,我在引用该包的项目的 csproj 中添加了以下配置:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
</PackageReference>
Run Code Online (Sandbox Code Playgroud)
当我尝试通过运行 dotnet SicotX.dll 命令行(是主项目)来运行已发布的项目时,问题就出现了。该应用程序尝试运行但不执行任何操作
我检查添加到应用程序的日志,这是堆栈跟踪列表:
2022-03-02T21:31:07.8101308-05:00 [INF] () Creating the web host ...
2022-03-02T21:31:09.0961070-05:00 [FTL] (Microsoft.AspNetCore.Hosting.Diagnostics) Application startup exception
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
System.Reflection.ReflectionTypeLoadException: …
Run Code Online (Sandbox Code Playgroud) c# entity-framework-6 entity-framework-core asp.net-core asp.net-core-6.0
我正在我工作的公司解决方案中实现存储库模式,将后端项目和数据库上下文中的模型类以及DbContexts项目中的迁移分开。
我正在使用Scaffold-DbContext将后端项目设置为模型类目标的默认项目,但是DbContext类始终与模型类在同一文件夹中创建。是否可以将DbContext类的创建重定向到其他输出文件夹,就我而言,重定向到DbContexts项目?
我正在使用 monodevelop 5.9.6 开发 ASP.NET MVC Razor 项目,并添加了捆绑 ( System.Web.Optimization
)所需的所有包,在BundleConfig
我添加
bundles.add(ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
Run Code Online (Sandbox Code Playgroud)
和别的。在Global.asax.cs
我打电话
BundleConfig.RegisterBundles(BundleTable.bundles);
Run Code Online (Sandbox Code Playgroud)
然而在 _Layout.cshtml
@Scripts.Render("~/bundles/jquery")
Run Code Online (Sandbox Code Playgroud)
渲染为
<script src="/bundle/jquery?v=5GM9HLcujnDGm6SNVq0Es63_cXK2viQ4_nYEpm02Ls1"></script>
Run Code Online (Sandbox Code Playgroud)
运行时,导致"Failed to load resource (404)"
javascript 错误,因为所有 jquery 的文件都没有按应有的方式呈现。
我需要渲染所有 jquery 文件和样式文件。
我想为 asp.net core 2.1 项目以西班牙语提供身份用户名和密码错误消息的本地化字符串,因为它总是以英语显示消息。我按照http://www.ziyad.info/en/articles/20-Localizing_Identity_Error_Messages中的说明进行了尝试,但对我不起作用。
谢谢
最近我使用VS2017创建了一个ASP.NET Core(多平台)项目和一个用于管理SQL Server数据库模型的ClassLibrary.
实际上我们在生产服务器中有一个数据库,我需要使用dotnet ef dbcontext scaffold [arguments] [options] ...命令行生成类,但是我需要在创建DbContext类时单一化类名.
请,需要帮助!谢谢
最近我将我的 asp.net core 3.1 Web 应用程序迁移到 NET6。在迁移之前,我没有遇到此类问题。我的网络应用程序有几个项目(DLL),其中一些项目由于要求而具有视图和控制器。我将这些项目标记为 Skd.Razor,如下所示:
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我将 Startup 配置为使用应用程序部件来识别这些控制器和视图:
每个项目都有自己的 _ViewImports.cshtml 包括主项目 SicotX:
当我尝试发布应用程序时出现问题,编译生成以下错误
_ViewImports.cshtml 导致除主 SiotX 项目外的两个项目中的输出路径发生冲突。
我需要在这些项目中使用 _ViewImports,所以我需要您的帮助或指导如何克服这个阻碍我的问题,或者是否可以使用独特的 _ViewImports.cshtml 并与所有项目共享?
谢谢
c# ×10
asp.net-core ×4
asp.net ×2
asp.net-mvc ×2
.net ×1
.net-6.0 ×1
access-token ×1
itext ×1
itext7 ×1
javascript ×1
jwt ×1
mono ×1
monodevelop ×1
nestjs ×1
node.js ×1
schannel ×1
ssl ×1
sspi ×1
token ×1