我在Web MVC中使用带有OWIN身份验证的Web API.我<authentication>在Web.Config中使用我的Web MVC,所以它重定向到登录页面.
<authentication mode="Forms">
<forms name="WEB.AUTH" loginUrl="~/login" domain="" protection="All"
timeout="43200" path="/" requireSSL="false" slidingExpiration="true" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我正在使用[System.Web.Http.Authorize]属性来授权我的Web API.但不知何故,由于上述配置,API重定向到登录页面,就像我的MVC应用程序一样.
我想要做的是保持重定向Web MVC的功能,但返回401 for Web API.我怎样才能做到这一点?我应该为Web API创建自定义授权属性吗?
- 编辑 -
我发现WebApi.Owin中的这篇文章SuppressDefaultHostAuthentication的答案也抑制了webapi之外的身份验证
所以我只想在我的脑中加几行Startup.cs.我的所有控制器都配置了"api"前缀路由.
HttpConfiguration config = new HttpConfiguration();
//..some OWIN configuration
app.Map("/api", inner =>
{
inner.UseWebApi(config);
});
Run Code Online (Sandbox Code Playgroud)
确保你放在app.Map()Web Api配置行之后.否则,它将给MVC应用程序带来错误.
我有CTE查询,上面有大量记录.以前它工作得很好.但最近,它给一些成员抛出了错误
声明终止.在语句完成之前,最大递归100已用尽.
所以我把OPTION (maxrecursion 0)或者OPTION (maxrecursion 32767)放在我的查询上,因为我不想限制记录.但是,结果是查询需要永远加载.我该如何解决这个问题?
这是我的代码:
with cte as(
-- Anchor member definition
SELECT e.SponsorMemberID , e.MemberID, 1 AS Level
FROM tblMember AS e
where e.memberid = @MemberID
union all
-- Recursive member definition
select child.SponsorMemberID , child.MemberID, Level + 1
from tblMember child
join cte parent
on parent.MemberID = child.SponsorMemberID
)
-- Select the CTE result
Select distinct a.*
from cte a
option (maxrecursion 0)
Run Code Online (Sandbox Code Playgroud)
编辑:删除不必要的代码,以便于理解
已解决:所以问题不是来自maxrecursion.它来自CTE.我不知道为什么,但可能它包含任何赞助商周期:A - > …
我正在建立移动网站,我想在移动浏览器,iPhone和iPad上运行该应用程序.是否有模拟器的下载链接?我更喜欢免费申请.