首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在ServiceStack.MVC身份验证中覆盖登录Url?

如何在ServiceStack.MVC身份验证中覆盖登录Url?
EN

Stack Overflow用户
提问于 2012-07-03 06:02:34
回答 3查看 609关注 0票数 1

如何覆盖登录Url?

你能把它作为属性添加到AuthenticateAttribute中吗?

EN

Stack Overflow用户

发布于 2012-07-03 06:04:14

在System.Web.Security.FormsAuthentication名称空间中:

代码语言:javascript
运行
复制
FormsAuthentication.LoginUrl

如果您想覆盖authorize值,只需实现您自己的Web.config属性:

代码语言:javascript
运行
复制
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class CustomAuthorize: AuthorizeAttribute{
    public override void OnAuthorization(AuthorizationContext filterContext) {
        //If the request does not provide authentication, then perform a redirect
        if (!filterContext.HttpContext.Request.IsAuthenticated) {
            var loginUrl = FormsAuthentication.LoginUrl; //Change your URL here if needed.

            filterContext.Result = new RedirectResult(loginUrl);
        } else {
            //Since the request was authenticated, perform the default authorization check.
            base.OnAuthorization(filterContext);
        }
    }
}
票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11301790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档