我已经在C#.net Core中的项目上启用了CORS
在startup.cs我添加行
...
services.AddCors();
...
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在另一个Blazor项目中使用API时,我在Host上我的API项目的日志中看到此错误
CORS协议不允许同时指定通配符(任何)来源和凭据。如果需要支持凭据,则通过列出各个来源来配置策略
我的代码在 Blazor
using (HttpClient http = new HttpClient()) {
http.DefaultRequestHeaders.Add("Authorization", "Token");
var response = await http.GetStringAsync("https://example.com?prm=2");
Console.WriteLine(response);
dynamicContent = response;
}
Run Code Online (Sandbox Code Playgroud)
在启用Cors之前,我在浏览器控制台中看到另一个错误
我可以为解决该问题做出哪些改变?
我可以删除文件夹C:\Program Files\dotnet\sdk\NuGetFallbackFolder\或将其移动到其他文件夹吗?(最好不在C盘中)
如果可以删除,如何删除?直接删除文件夹?有副作用或损害吗?
如果可以移动,该如何移动?目标文件夹像D:\NuGetFallbackFolder什么?我该怎么做?
当我启动服务(Docker容器中的.Net Core 2.2上的API)时,我得到了一个警告:
未配置XML加密器。密钥{daa53741-8295-4c9b-ae9c-e69b003f16fa}可以以未加密形式持久存储。
我没有配置DataProtection。我找到了配置DataProtection的解决方案,但不需要保存此密钥。对我来说,如果密钥只保留到应用程序重新启动,就可以了-没关系。但我不需要在日志中看到此警告
有任何想法吗?我们该怎么做?
我的启动类如下所示:
public class Startup {
public Startup(IConfiguration configuration) {
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services) {
services.AddMemoryCache();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddApiVersioning(o => o.ApiVersionReader = new HeaderApiVersionReader("api-version"));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
app.UseMvc();
lifetime.ApplicationStarted.Register(OnApplicationStarted);
lifetime.ApplicationStopping.Register(OnShutdown);
}
public void OnApplicationStarted() {
Console.Out.WriteLine($"Open Api Started");
}
public void OnShutdown() {
Console.Out.WriteLine($"Open Api is shutting down.");
}
}
Run Code Online (Sandbox Code Playgroud)
也许对我的项目包也有帮助
<ItemGroup> …Run Code Online (Sandbox Code Playgroud) 通过此链接,您可以阅读有关 ASP.NET Core 模块的信息
要将应用程序配置为进程内托管,请将属性添加到应用程序的项目文件中,其值为 InProcess(进程外托管使用 OutOfProcess 设置)
我读了好几遍,但我不明白这是什么意思?
何时必须使用 OutOfProcess,何时必须使用 InProcess?
这些模型的优缺点?
做决定时要依靠什么?
我找到了几个解决方案,我可以使用.Net RSA Provider使用公钥加密消息,并使用私钥解密.
但我想要的是使用私钥加密和使用公钥解密.
我希望将公钥存储在我的应用程序中并使用私钥加密许可证,例如在我的开发机器上,将其发送到应用程序并使用公钥解密信息.
我怎样才能做到这一点?
我创建了一条自定义路线
<Route
path="/course-plan/:plan_id/plan-lesson/:id"
render={props => {
return <LessonEditPage
{...props}
resource={'plan-lesson'}
record={{planId: props.match.params.plan_id}}
/>
}}
/>,
Run Code Online (Sandbox Code Playgroud)
LessonEditPage 具有带有 SimpleForm 的编辑组件
当我进入此页面时,我发出请求crudGetOne,本地一切都很好,我在用于发出请求的参数中有 id ,但是当我在服务器上部署此代码时,当我进入此页面时,params.id未定义
我不知道为什么以及可能出现什么问题
将我的 webapi dotnet 核心项目部署到 Ubuntu 服务器 通过 nginx 使用 kestrel 和代理进行配置
我的文件中的代码Program.cs
public class Program {
public static void Main(string[] args) {
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:5050")
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
创建文件/etc/nginx/sites-available/default并创建符号链接/etc/nginx/sites-enable/default
server {
listen 80;
location / {
proxy_pass http://localhost:5050;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
}
Run Code Online (Sandbox Code Playgroud)
我的文件位于 /etc/systemd/system/kestrel-project.service
[Unit]
Description=WebApi .NET …Run Code Online (Sandbox Code Playgroud) 我正在尝试在.NET Core 2.1 Web-API中进行模拟。因此,此Web-API使用HttpClient调用了另一个Web-API,我需要调用第一个的用户也必须是正在执行第二个的用户。同样的情况也可以在通过此调用运行完整框架的另一个Web-API中使用:
((WindowsIdentity)_httpContextAccessor.HttpContext.User.Identity).Impersonate()
Run Code Online (Sandbox Code Playgroud)
由于Impersonate().NET Core 2.1中没有此功能,因此我使用搜索了一些示例,WindowsIdentity.RunImpersonated并尝试了与此类似的不同版本的代码:
WindowsIdentity identity = (WindowsIdentity)m_contextAccessor.HttpContext.User.Identity;
HttpClient client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true });
await WindowsIdentity.RunImpersonated(identity.AccessToken, async () =>
{
var request = new HttpRequestMessage(HttpMethod.Get, url);
var response = await client.SendAsync(request);
});
Run Code Online (Sandbox Code Playgroud)
这将引发错误,client.SendAsync错误消息是这样的:
在此调用仍在处理期间,已对WSALookupServiceEnd进行了调用。呼叫已被取消---> System.Net.Http.HttpRequestException
堆栈跟踪的开始:
在System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32端口,CancellationToken cancelleToken)-内部异常堆栈跟踪的结尾-在System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32端口,CancellationToken System.Threading.Tasks.ValueTask`1.get_Result()处的System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage请求,CancellationToken cancelleToken)
是否有其他人看到此错误或对如何解决此问题有任何见解?我尝试了不同版本的代码来RunImpersonated与HttpContext用户调用,并且都导致了相同的错误。
感谢您的输入
我在Blazor有一个项目
在客户端,我想读取哈希参数
我知道如何在JavaScript中进行操作-但我的问题是在Blazor项目的c#客户端中如何进行操作
例如,我有一个URL http:// localhost:5060 /#token = 12345678
怎么服用token?
我在index.cshtml中的代码
@page "/"
@inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper
<h1>Hello, world!</h1>
url is @Url
@functions {
protected override void OnInit() {
Url = GetUrl();
}
public string Url { get; set; }
public string GetUrl() {
return ?;
}
}
Run Code Online (Sandbox Code Playgroud) 我更改了连接 Oracle 的驱动程序并收到错误
连接字符串格式不正确
我有非官方的 Oracle 驱动程序dotNetCore.Data.OracleClient Version=1.0.0
现在我用Oracle.ManagedDataAccess.Core Version=2.18.3
我的连接字符串看起来像那里
Data Source = ORACLE.HOSTS:1521/pdb_prod;PERSIST SECURITY INFO=True;USER ID=xxxx; Password=xxxx;Pooling=false;
Run Code Online (Sandbox Code Playgroud)
而且之前效果很好
我的连接字符串有什么问题吗?
.net-core ×7
c# ×6
blazor ×2
.net ×1
asp.net-core ×1
cryptography ×1
kestrel ×1
nginx ×1
oracle ×1
oracle12c ×1
react-admin ×1
reactjs ×1
rsa ×1
ubuntu ×1