任何人有这个问题我改变Pc并尝试安装网络核心框架但是vs代码返回此信息当我试图写dontet --info
Failed to load the dll from [C:\Program
Files\dotnet\host\fxr\2.1.0\hostfxr.dll], HRESULT: 0x80070057
The library hostfxr.dll was found, but loading it from C:\Program
Files\dotnet\host\fxr\2.1.0\hostfxr.dll failed
- Installing .NET Core prerequisites might help resolve this problem.
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
Run Code Online (Sandbox Code Playgroud) 有人知道如何使用MatchCollection找到由字母组成的最长子字符串.
public static Regex pattern2 = new Regex("[a-zA-Z]");
public static string zad3 = "ala123alama234ijeszczepsa";
Run Code Online (Sandbox Code Playgroud) 我用 async await 写了一些简单的代码,但是当我尝试运行它时,编译器抛出一个System.InvalidOperationException.
完整的错误信息是:
未处理的异常:System.InvalidOperationException:ContentType 中提供的字符集无效。无法使用无效字符集将内容读取为字符串。
System.ArgumentException: 'ISO-8859-2' 不是受支持的编码名称。有关定义自定义编码的信息,请参阅 Encoding.RegisterProvider 方法的文档。
编码:
class Program
{
static async Task Main(string[] args) => await asyncDoItAsync();
private static async Task<string> asyncDoItAsync()
{
HttpClient client = new HttpClient();
Task<string> url = client.GetStringAsync("http://google.pl");
while(!url.IsCompleted)
{
WhenWaiting();
}
string url_length = await url;
return url_length;
}
private static void WhenWaiting()
{
Console.WriteLine("Waiting ...");
Thread.Sleep(90);
}
}
Run Code Online (Sandbox Code Playgroud) 嗨,我遇到了 cors 错误问题,我阅读了堆栈和其他网站上的所有示例,但没有任何帮助。我用net core 2.1和客户端应用程序编写了其余的api(我使用react框架),我尝试从rest api中获取api,所有这些都在本地主机上。在服务器的http://本地主机:44334和响应客户端的http://本地主机:3000 当我尝试在服务器上提取API,我得到这个异常:
Microsoft.AspNetCore.Cors.Infrastructure.CorsService:信息:策略执行失败。Microsoft.AspNetCore.Cors.Infrastructure.CorsService:Information: CORS 策略中不允许请求标头“access-control-allow-origin”。Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: 请求在 3.9493ms 204 内完成
但是在浏览器上的反应客户端上,我得到了这个:
访问以获取“ https://开头本地主机:44334 /帐户”从原点“的http://本地主机:3000 ”已被封锁的CORS政策:回应预检要求未通过访问控制检查:没有“访问控制-Allow-Origin' 标头存在于请求的资源上。如果不透明响应满足您的需求,请将请求的模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。
这是我注册 cors 时的 c# 类,我记得在 .AddMvc 方法后面注册实例
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddAuthorization(options =>
{
options.AddPolicy("RequireAdministratorRole", policy => policy.RequireRole("Administrator"));
});
services.AddCors();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddOptions();
services.AddMemoryCache();
var jwt_settings = Configuration.GetSettings<JwtSettings>();
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(cfg =>
{
cfg.TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt_settings.Key)),
ValidIssuer = jwt_settings.Issuer, …Run Code Online (Sandbox Code Playgroud) 当我尝试在我的程序中验证电子邮件和电话号码时,我有这样的例外。
错误:正则表达式写得正确,我不知道问题出在哪里。
我读了最后一篇文章,但在我的情况下有任何工作。
消息:System.ArgumentException:解析 '{2}[0-9]-{3}[0-9]' - 量词 {x,y} 不带任何东西。
public class Order
{
public string EmailValidationPattern = "{2}[0-9]-{3}[0-9]";
public string ZipCode { get; set; }
public string PhoneNumber { get; set; }
private void SetZipCode(string zipCode)
{
if (Regex.Match(zipCode, EmailValidationPattern).Success)
{
ZipCode = zipCode;
}
}
private void SetPhoneNumber(string number)
{
if (Regex.Match(number, @"^(\+[0-9]{9})$").Success)
{
PhoneNumber = number;
}
}
}
Run Code Online (Sandbox Code Playgroud)