问题标签 [asp.net-apicontroller]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
asp.net-mvc - 如何将当前会话从 MVC 控制器发送到 APIController?
我在 MVC 控制器中创建了一个会话,但现在我必须在其他 ApiController 中使用该会话。问题是 MVC Controller 的上下文与 ApiController 不同,那么有没有办法将当前 Session 信息从 MVC Controller 发送到 ApiController?
我当前的会话包含用户 ID 和用户名
c# - IdentityServer3 - 由于 CORS 路径无效而被拒绝
我们有一个 ASP.NET MVC 应用程序正在对 IdentityServer3 进行身份验证而没有问题,但是如果用户在大约 3 分钟后继续使用 AJAX 功能之前等待,则使用 ApiController 的应用程序的 Web API 部分开始失败(在 3 分钟之前一切似乎都很好) .
在 Chrome 中看到的错误是:
XMLHttpRequest 无法加载 https://test-auth.myauthapp.com/auth/connect/authorize?client_id=ecan-farmda …gwLTk5ZjMtN2QxZjUyMjgxNGE4MDg2NjFhZTAtOTEzNi00MDE3LTkzNGQtNTc5ODAzZTE1Mzgw。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问来源“ http://test.myapp.com ”。
在 IE 上,我收到以下错误:
SCRIPT7002:XMLHttpRequest:网络错误 0x4c7,操作已被用户取消。
查看 IdentityServer3 的日志,我看到如下条目:
2015-08-10 16:42 [警告] (Thinktecture.IdentityServer.Core.Configuration.Hosting.CorsPolicyProvider) 对路径的 CORS 请求:/connect/authorize from origin: http://test.myapp.com但因无效而被拒绝CORS 路径
在 IdentityServer3 Web 应用程序中,我给客户端 AllowedCorsOrigins:
在注册服务时,我添加了一个 InMemoryCorsPolicyService:
我确实注意到 IdentityServer3 日志条目说“为路径发出的 CORS 请求:/connect/authorize”而不是“为路径发出的 CORS 请求:/ auth /connect/authorize”。但是查看 IdentityServer3 源代码表明这可能不是问题所在。
也许 InMemoryCorsPolicyService 没有被接收?
关于为什么事情不适用于称为 ApiController 的 AJAX 的任何想法?
Thinktecture.IdevtityServer3 v1.6.2 已使用 NuGet 安装。
更新
我正在与 IdentityServer3 开发人员进行对话,但仍然无法解决问题。如果有帮助:
https://github.com/IdentityServer/IdentityServer3/issues/1697
jquery - getJSON only getting first element of returned array
I have a api controller function that returns an array of objects. The following is how I call my function and an example of what happens:
The first element contains the correct values as illustrated but all other elements are null. data.length
returns the correct size of the array and I have verified that my controller is returning the values I anticipate. Am I missing something here???
UPDATE: Here is my controller method:
As mentioned I have verified that the array being returned contains the correct values.
JSON response is this:
So as you can see elements 2 and 3 just have this "ref" value in them...not sure why??
UPDATE #2:
Tried $.get
rather than $.getJSON
without success, same issue.
I also tried making the following changes to the controller:
I still experience the same issue.
asp.net-mvc - ASP NET 属性路由数组
所以我正在为我的控制器使用属性路由,如下所示:
现在我想将其转换为接受整数数组,在控制器参数中我只是切换到[FromUri] int id[]
没有问题,但是,如何切换路由属性[Route("last/{id:int}")]
以使其接受整数数组?
c# - 将 HashSet 发送到 C# ApiController
我有一个MyObject
带有HashSet
属性的 C# 对象。我在客户端对其进行序列化,然后通过GET
URI 中的参数将其发送到 C# ApiController
,它接受对象作为参数:
这一切都使用 a 工作得非常好List
,但是现在我使用 a HashSet
,客户端序列化并发送对象,但服务器收到一个空的HashSet
.
ApiController
C#接收HashSets
和Lists
通过 URI的方式有关键区别吗?
azure - Azure 移动应用中的 TableController 与 ApiController
我刚刚开始使用移动应用程序。我习惯于使用ApiController
Web API 制作 API。
VS2015 中移动应用的默认项目模板带有一个TodoItemController
继承自TableController
. 看起来有一些开箱即用的 CRUD 操作安装在其中,TableController
并且每个数据对象必须是 type ITableData
。
理想情况下,我想以TableController
自己的方式跳过和实现ApiController
.
我的问题是,如果有的话,放弃的后果是TableController
什么?应用服务与使用之间是否存在紧密耦合TableController
?
c# - 如何最好地将 ApiController 与 Owin Bearer Token 一起使用来刷新 Bearer Token
我们有一个 AJ 网站
,它通过 C# WebApp 访问数据,它只是使用 ApiController
并且它使用 Owin 持有者令牌来允许 AJ 客户端代码访问 API。
API 仅供 AJ 网站访问,
并处理要使用的令牌的登录和返回。
生成令牌和声明的位置是由主 Web api 在内部调用的第二个 Web 应用程序。
我们想要做的是在 Main Api 上创建一个请求,
其中可以传递经过身份验证的令牌
我们使用声明来了解身份
并返回更新的承载令牌
以便更新任何角色或过期时间
那么,将提供给主 Web api 的不记名令牌重新传递
给令牌服务并让它创建新的不记名令牌的最佳方法是什么?
我们是否更新了简单的身份验证服务提供者?还是我们和一个新的 api 调用了我们回忆的令牌服务,并生成了新的不记名令牌?
什么是最佳选择,我们如何实施?
感谢有关该主题的任何想法或帮助,谢谢。从我所看到的情况来看,有很多这种用法的例子,但没有一个看起来完全符合实际用法。
此外,它们似乎允许使用 AJ 站点存储或在 cookie 中的刷新令牌。
一些示例表明,可以在过期后进行刷新。
我们想在不记名令牌过期之前查看它的刷新。
如果过期,则只需要重新登录。
asp.net-web-api - 将 HttpRequestBase 作为参数传递
我有一个 GetIP() 方法,它将 System.Web.HttpRequestBase 作为参数。任何人都可以帮助我如何获取 HttpRequestBase 对象。
我认为这真的很基本,但无法弄清楚。
谢谢你。
asp.net-mvc - ASP.NET Web API 日期时间绑定
我将带有日期值“02/11/2015”(DD/MM/YYYY)的 JSON 对象提交给 API 控制器。由于某种原因,它在装订时被转换为美国格式(2 月 11 日)。我在同一个解决方案中有标准的 MVC 控制器,它正确地绑定了以相同格式提交的日期值(英国)。什么会导致这种差异:
以下是标准 MVC 提交标头:
并形成数据
这是 API 调用标头
和我传递的 JSON 对象