MVC ServiceStackController不遵守ServiceStack基本身份验证HtmlRedirect [英] ServiceStack Basic Authentication HtmlRedirect is not respected by MVC ServiceStackController

查看:105
本文介绍了MVC ServiceStackController不遵守ServiceStack基本身份验证HtmlRedirect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能不太了解,但存在以下问题:

I'm probably not understanding something but I have the issue below:

AppHost.cs

Plugins.Add(new AuthFeature(
            () => new AuthUserSession(),
            new IAuthProvider[] { new BasicAuthProvider() }) { HtmlRedirect = null });

HomeController.cs

[Authenticate]
public class HomeController : ServiceStackController

问题

问题在于,当我尝试访问HomeController时,我被重定向到~/login?redirect=.....

The issue is that when I try to access the HomeController, I am redirected to ~/login?redirect=.....

我认为通过将HtmlRedirect设置为null,也会影响MVC控制器,但似乎没有.

I would assume that by setting HtmlRedirect to null, would also affect the MVC controllers too, but it doesn't seem to.

这是预期的行为吗?还是我做错了什么?

我的最终目标是使浏览器出现带有质询/响应基本身份验证框的提示.

My end goal is to have the browser prompt with a challenge / response basic auth box.

推荐答案

由于此提交您可以在身份验证失败时覆盖默认行为:

Since this commit you are able to override the default behavior when authentication failed:

[Authenticate]
public class HomeController : ServiceStackController
{
    public override ActionResult AuthenticationErrorResult
    {
        get
        {
            //return 401 Unauthorized for example
            return new HttpStatusCodeResult(401);
        }
    }
}

ServiceStackController.AuthorizationErrorResult可以用相同的方式修改.

ServiceStackController.AuthorizationErrorResult can be modified in the same way.

在这种情况下无法将HtmlRedirect设置为null,因为与ASP.net MVC控制器(而不是ServiceStack服务)一起使用时,[Authenticate]属性(和所有其他ServiceStack属性)的行为略有不同.

Setting HtmlRedirect to null doesn't work in this case, because the behavior of the [Authenticate] attribute (and all other ServiceStack attributes) is slightly different when used with ASP.net MVC controllers instead of ServiceStack services.

这篇关于MVC ServiceStackController不遵守ServiceStack基本身份验证HtmlRedirect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆