【问题标题】:{StatusCode: 500, ReasonPhrase: 'Internal Server Error' in sso Api call forms authentication{StatusCode:500,ReasonPhrase:sso Api 调用表单身份验证中的“内部服务器错误”
【发布时间】:2017-04-11 14:02:41
【问题描述】:

这里我在 web.config 中使用表单身份验证:

   <forms loginUrl="~/LogOn" timeout="2880" defaultUrl="~/Home/Index" name=".ASPXAUTH" protection="All" path="/" enableCrossAppRedirects="true" domain=".xyz.com" />

</authentication>
<authorization>
  <deny users="?" />
</authorization>

问题是:(这里我调用 api url..但它不会调用正确的方式..而是会重定向到其他 url,如下所示)

var response = client.GetAsync(apiUrl).Result;

这里是 apiUrl:

http://localhost:1849/Api/Ticket?UserId=10&start=0&length=10&searchstr=&orders=0&orderDir=asc

但它不会调用这个 api,而是调用

http://localhost:1849/LogOn?ReturnUrl=%2fApi%2fTicket%3fUserId%3d10%26start%3d0%26length%3d10%26searchstr%3d%26orders%3d0%26orderDir%3dasc&UserId=10&start=0&length=10&searchstr=&orders=0&orderDir=asc

那么我怎么调用上面的api???

【问题讨论】:

    标签: c# api asp.net-mvc-5


    【解决方案1】:

    从外观上看,您已经拒绝了整个网站上的匿名用户。您需要先进行身份验证。

    您可以使用 web.config 中的位置标签来允许匿名访问您的登录页面,这样您就可以对其进行身份验证,然后它将允许访问您的 api。

    由于您使用的是 API,因此您可能需要使用与登录页面不同的身份验证方法。

    【讨论】:

    • 好的,但是我该如何验证呢??
    • 你想如何选择是否有人可以访问你的api?
    • 先生,我从不同的项目登录..并使用表单身份验证 Iprincple 存储凭据并使用相同的东西在这里登录...你想做 [Authorize(Roles = "Admin, SubAdmin")]..如果我在 web.config 中删除上述表单身份验证,那么它将正常工作
    • 有什么方法可以停止..重定向吗??
    • 您能否更改您的身份验证 cookie 以使用通配符域(假设您的 api 在子域上)?您重定向的原因是因为它们没有经过身份验证,并且您的配置告诉它返回登录页面。
    猜你喜欢
    • 1970-01-01
    • 2019-12-15
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多