我正在使用果园核心在asp网络核心网络应用程序项目。我有一个控制器,有两个简单的get和post Apis。由于我使用的是OrchardCore,所以Startup.cs文件具有不同的配置,并且在configureServices中不使用services.AddControllers()。在我使用HttpGet之前,一切都很好。但当我想和HttpPost一起吃苹果的时候,postMan说,badRequest说。因此,我在services.AddControllers()中添加了Startup.cs,post Api在post中也很好,但是果园项目说我有多个终结点。我使用了services.AddMvc().AddNewtonsoftJson(),每件事情都很好,但是管理页面没有加载,并且有以下错误:
InvalidOperationException:没有找到“索引”视图。搜索了以下位置: /Areas/OrchardCore.AdminDashboard/Views/Dashboard/Index.cshtml /Areas/OrchardCore.AdminDashboard/Views/Shared/Index.cshtml /Views/Shared/Index.cshtml /Pages/Shared/Index.cshtml
如果你能帮我打电话给波斯特阿皮,我会很感激的。这是我的代码:
[HttpPost("post")]
public Task<string> post()
{
return Task.FromResult("hiPost");
}
[HttpGet("get")]
public Task<string> get()
{
return Task.FromResult("hiGet");
}这是我的startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
//services.AddControllers();
services.AddOrchardCms();
services.AddMediatR(typeof(SelectedWebSiteBlogQueryHandler).Assembly);
services.AddAutoMapper(typeof(Startup));
services.AddCors();
services.AddMvc().AddNewtonsoftJson();
}
public void Configure(IApplicationBuilder app, IHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(o => o.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseOrchardCore();
}
}发布于 2021-05-09 11:39:13
您可能在控制器上缺少了一个IgnoreAntiForgeryToken属性。
默认情况下,AntiForgery由OrchardCore启用
对于ApiController中的OrchardCore,我希望看到控制器的装饰如下。
[ApiController]
[Authorize(AuthenticationSchemes = "Api"), IgnoreAntiforgeryToken, AllowAnonymous]但是,这取决于您是使用OpenId模块进行身份验证,还是只需要在不使用AuthenticationScheme的情况下将其发送到普通控制器。
根据您在现实生活中实际发布的内容而定,最好在您的帖子中提供一个防伪造令牌。
https://stackoverflow.com/questions/67457135
复制相似问题