Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hardy Wang 91 posts 112 karma points
    Mar 21, 2014 @ 15:50
    Hardy Wang
    0

    Public Access (form auth) and 401 code

    I set some node to request role based access credential, and I built a login page to accompany with the settings.

    My question is if login fails is there a way I can simply throw 401 code from that login page I built without displaying anything or use setting in web.config <forms name="yourAuthCookie" loginUrl="login.aspx" protection="All" path="/" />

    Currently if my code in my login page is

    if (this.Authenticate(username, password))
    {
        Response.Redirect(contentPageUrl, false);
    }
    else
    {
        Response.StatusCode = 401;
        Response.End();
    }
    private bool Authenticate(string username, string password)
    {
        if (Membership.ValidateUser(username, password))
        {
            FormsAuthentication.SetAuthCookie(username, false);
            return true;
        }
    
        return false;
    }

    Then Umbraco tries to use /login.aspx as set in config file

    Or if my code is

    if (this.Authenticate(username, password))
    {
        Response.Redirect(contentPageUrl, false);
    }

    It just show the same custom login page again.

Please Sign in or register to post replies

Write your reply to:

Draft