草庐IT

ASPNetCore

全部标签

xml - ASPNetCore API 内容协商不起作用

我正在尝试设置我的api,以便它根据Acceptheader使用XML或JSON进行响应。我正在学习ShawnW的教程:https://wildermuth.com/2016/03/16/Content_Negotiation_in_ASP_NET_Core它说要添加一个包到:"Microsoft.AspNet.Mvc.Formatters.Xml":"6.0.0-rc1-final"但我找不到它,所以安装了:Microsoft.AspNetCore.Mvc.Formatters.Xml他说要将它添加到Startup的配置服务部分://Addframeworkservices.serv

c# - ASP.NET Core 2.1 中的数据保护仅适用于一台机器

我正在使用ASP.NETCoreDataProtectionsystem使用应用程序A加密数据并使用应用程序B解密数据。在开发机器上运行时,加密和解密都可以工作,但是当应用程序B移动到生产机器时,它不再能够解密,因为IDataProtector.Unprotect方法抛出异常:System.InvalidOperationException:Thekeyringdoesnotcontainavaliddefaultprotectionkey.Thedataprotectionsystemcannotcreateanewkeybecauseauto-generationofkeysisd

c# - 更改单个 ASP.NET Core Controller 的 JSON 序列化设置

我有两个ControllerController:ControllerA和ControllerB。每个Controller的基类是Controller。ControllerA需要以默认格式(camelCase)返回JSON。ControllerB需要以不同的JSON格式返回数据:snake_case。如何在ASP.NETCore3.x和2.1中实现它?我尝试了startup:services.AddMvc().AddJsonOptions(options=>{options.SerializerSettings.Converters.Add(newStringEnumConverter

c# - 用户 : (null) 授权失败

我正在为不使用Identity的ASP.NETMVCCore使用自定义身份验证。这是Startup.cs:publicclassStartup{publicIConfigurationConfiguration{get;set;}//ConfigureIoCcontainer//https://docs.asp.net/en/latest/fundamentals/dependency-injection.htmlpublicvoidConfigureServices(IServiceCollectionservices){services.Configure(options=>Con

c# - .net 核心 'Response.Cookies.Append' 不作为某个站工作

我正在按照ASP.NETCore2.1文档(https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#implement-a-strategy-to-select-the-languageculture-for-each-request)中的建议使用“Response.Cookies.Append”来设置文化。它在我的工作站上运行得非常好。但是当我的同事获取我的更改时,它不起作用。在调试过程中,我发现“Response.Cookies.Append”没有添加co

c# - 使用 Identity 2.0 数据库对 ASP.NET Core 1.0 应用程序进行身份验证

我正在尝试创建一个新的ASP.NETCore1.0Web应用程序,我希望它使用我已经设置的身份验证表。这些表最初是由使用Microsoft.ASPNet.Identity.EntityFramework2.2.0的ASP.NET4.6Web应用程序创建的看起来Microsoft.AspNetCore.Identity.EntityFrameworkCore中的情况发生了变化因为新的Core1.0应用程序在尝试登录时会抛出此错误:处理请求时数据库操作失败。SqlException:列名“NormalizedUserName”无效。列名“ConcurrencyStamp”无效。列名称“Lo

c# - .Net Core 中的 .AspNetCore.Antiforgery.xxxxxxx cookie 是什么?

我试图在.NetCore中使用ValidateAntiForgeryToken,但我得到的是.AspNetCore.Antiforgery.xxxxxxxcookie丢失。这个.AspNetCore.Antiforgery.xxxxxxxcookie是什么? 最佳答案 ASP.NETCore查找此cookie以找到X-CSRFtoken。TheValidateAntiForgeryTokenisanactionfilterthatcanbeappliedtoanindividualaction,acontroller,orgloba

c# - 如何设置 SwashBuckle.AspNetCore.Swagger 以使用授权?

我已经使用Swashbuckle.AspNetCore.Swagger记录了我的api,我想使用swaggerui测试一些具有Authorize属性的资源。接口(interface)usingMicrosoft.AspNetCore.Authorization;usingMicrosoft.AspNetCore.Mvc;usingSystem.Linq;namespaceApi.Controllers{[Route("[controller]")][Authorize]publicclassIdentityController:ControllerBase{[HttpGet]publi

c# - 找不到 Microsoft.AspNetCore.Antiforgery

我正在将asp.netcore2.0网站部署到IIS10。我已确保我的应用在program.settings文件中使用正确的ISS配置。publicclassProgram{publicstaticvoidMain(string[]args){BuildWebHost(args).Run();}publicstaticIWebHostBuildWebHost(string[]args)=>WebHost.CreateDefaultBuilder(args).UseKestrel().UseContentRoot(Directory.GetCurrentDirectory()).UseI

c# - Visual Studio .net 核心标签助手不工作

好吧,让我们开始吧。我正在使用VisualStudio2015和ASP.NET核心标签助手已经完全停止工作,不知道为什么,因为我没有改变任何东西。有一天我在工作,他们工作得很好,然后我第二天来了,现在没有任何ASP.NET核心Web项目显示任何标签助手!?!我已经尝试创建一个全新的ASP.NET核心mvc项目,但它们也在那里不起作用!!!我完全被卡住了,是否有一些设置可以在VisualStudio中完全关闭它们?请注意,我已经根据大多数其他帖子检查了通常会导致此问题的所有内容。我的_ViewImports有一行:-@addTagHelper*,Microsoft.AspNetCore.