ServiceStack Basic Authentication HtmlRedirect is not respected by MVC ServiceStackController

做~自己de王妃 提交于 2019-12-11 08:47:56

问题


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

The issue

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

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

Is this expected behaviour? or is am I doing something wrong?

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


回答1:


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 can be modified in the same way.

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.




回答2:


I have been on the ServiceStack Jabbr chat page and was told that this is a bug and a fix will be put on today!

https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.FluentValidation.Mvc3/Mvc/ExecuteServiceStackFiltersAttribute.cs#L25



来源:https://stackoverflow.com/questions/15654994/servicestack-basic-authentication-htmlredirect-is-not-respected-by-mvc-servicest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!