locked
Login Authenticate RRS feed

  • Question

  • User-1499457942 posted

    Hi

       By Default Default page is loaded if User is not authenticated user should be directed to Login page. If user directly enters the URL it should be checked whether user has Login or not . I am using VS2015 & don't want to use Membership

    Thanks

    Wednesday, December 23, 2015 8:32 AM

All replies

  • Wednesday, December 23, 2015 8:58 AM
  • User-1499457942 posted

    Hi

       When i make below changes in Web.Config & when i click on Login Button in Login Page i get the below error

    Error: {"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}

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

    [WebMethod]
            public static int chkLogin(string usercode, string pwd)
            {
                int id;
                BAL.UsrLogin __objectdata = new BAL.UsrLogin();
                id = __objectdata.chkLogin(usercode, pwd);
                return id;
            }
    
    <script type="text/javascript">
            $(document).ready(function () {
                $("#usercode").focus();
                $("#Submit").click(function () {
                    var usercode = $("#usercode").val().trim();
                    var pwd = $("#pwd").val().trim();
                    if (usercode == '') {
                        $("#usercode").focus();
                    }
                    else if (pwd == "")
                    {
                        $("#pwd").focus();
                    }
                    else if (pwd == "" || usercode == '')
                    {
                        $("#usercode").focus();
                    }
                    else {
                         $.ajax({
                            type: "POST",
                            url: "Login.aspx/chkLogin",
                            data: "{'usercode':'" + usercode + "', 'pwd': '" + pwd + "'}",
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            success: function (response)
                            {
                                switch (response.d) {
                                    case 1:
                                        window.location.href = "Transporter.aspx";
                                        break;
                                    default:
                                        alert('error');
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                alert("Status: " + textStatus); alert("Error: " + XMLHttpRequest.responseText);
                            }
                        });
                    }
                });
            });
        </script>

    Thanks

    Wednesday, December 23, 2015 9:21 AM
  • User1724605321 posted

    Hi JagjitSingh,

    About Error 401: If you are using forms authentication remember to allow anonymous access to your login page by doing this on your web.config:

    <location path="Login.aspx">
      <system.web>
        <authorization>
          <allow users="*"/>
        </authorization>
      </system.web>
    </location>

    Hope it helps.

    Best Regards,

    Nan Yu

    Thursday, December 31, 2015 9:08 AM
  • User-1499457942 posted

    Hi

       Still not working giving same error

    <authentication mode="Forms">
          <forms loginUrl="Login.aspx" timeout="2880" defaultUrl="default.aspx" />
        </authentication>
        <authorization>
          <deny users="?" /> 
          <allow users="*"/>
        </authorization>


    Thanks

    Monday, January 4, 2016 8:59 AM