0

Question 1: Login page - I want a popup to occur that says to re-enter credentials if the user puts in the wrong info.

Question 2: Logout Function - I need to end the users session when they click the logout button. Can someone please tell me exactly what to put in the Logout.aspx.cs and the Logout.aspx pages?

Code behind for Login page:

   protected void btnLogin_Click1(object sender, EventArgs e)
    {

        ThisWS.Client client = new ThisWS.Client();
        //client.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://svcThisService.svc/soap");
        WSAccess.ThisWS.clsTypesAuthResult response = client.Auth(this.txtUsername.Text, this.txtPassword.Text, txtAuthCode.Text);
        client.Close();
        this.lblErrorMessage.Text = response.Error;
        this.lblToken.Text = response.Token.ToString();
        int?[] cases = response.CaseNum;

        //Session.Add("Username", this.txtUsername.Text);   //User must re-login after an hour, since the token expires.
        //Session.Add("Password", this.txtPassword.Text);
        //Session.Add("AuthCode", this.txtAuthCode.Text);

        Session.Add("Token", response.Token);
        Session.Add("TokenExpires", DateTime.Now.AddHours(1));
        Session.Add("Cases", cases);
        Session.Add("PartyNameId", response.PartyNameID);

        Response.Redirect("ListCases.aspx");

.ASPX code I have for the login form:

<p class="redtext">Please use the form below to login.</p>

 <div class="">

<form id="form1" runat="server">
<div>

    <table class="auto-style1">
        <tr>
            <td class="auto-style2">Your Username:</td></tr>
        <tr>
            <td>
                <asp:TextBox ID="txtUsername" runat="server" Width="241px" MaxLength="255"></asp:TextBox>
            </td>
            <td>&nbsp;</td>
        </tr>
        <td>&nbsp;</td>
        <tr>
            <td class="auto-style2">Your Password:</td></tr>
        <tr>
            <td>
                <asp:TextBox ID="txtPassword" runat="server" Width="239px"></asp:TextBox>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td class="auto-style2" hidden="hidden">Authentication code: </td>
            <td>
                <asp:Label ID="txtAuthCode" runat="server" Width="244px" Visible="False">000</asp:Label>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>

            <td>
                <asp:Button ID="btnLogin" runat="server" Text="Click Here to Login" class="btn btn-primary btn-block" Width="175px" OnClick="btnLogin_Click1" />
            </td>
            <td>&nbsp;</td>
        </tr>

       </table>

</div>
</form> 
</div>
Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
LadyLuck
  • 53
  • 1
  • 7

1 Answers1

0

1) Use a function that has an alert in the OnClick event of the login Button. I would use a javascript function to verify the credentials, then alert if the credentials are incorrect

e.g.

<asp:Button ID="btnLogin" runat="server" Text="Click Here to Login" class="btn btn-primary btn-block" Width="175px" OnClick="verifyCredentials()" />

In the JavaScript:

function verifyCredentials() {
    if ( credentials != correctCredentials ) {
          alert('Please Enter Correct Credentials')
    else
          //proceed

Best Practice is not to use the OnClick event however. Using event listeners in JavaScript or binding events using jQuery:

JavaScript:

element.addEventListener(type, handler, false);

jQuery

$('#btnLogin').click(function() { ..... });

If you do not have JavaScript experience, go to this link: http://www.w3schools.com/js/DEFAULT.asp

This should help you become more familiar with the language and uses.

2) I'm not too familiar, but the solutions have been covered extensively on StackOverflow. Here are some links that should point you in the right direction:

How to kill the Session of User when he LoggedOut in ASP.NET

How to end the user session and make sure that the user is logged out?

Community
  • 1
  • 1
kylealonius
  • 223
  • 2
  • 9
  • Don't make use of `OnClick`, its good practice to incorporate this via jQuery - `$('#btnLogin').click(function() { ..... });` instead. It helps keeping design separate. – Dayan Apr 11 '14 at 18:03
  • There was no mention of the use of jQuery. It is a great tool, and one that I use. It is not always best to give an answer which will require an additional library(jQuery) and additional understanding to use that library. This can also been done by adding event listeners to the button using regular javascript without using jQuery. – kylealonius Apr 11 '14 at 18:07
  • 1
    Correct, but its also good to direct someone new towards good practices. – Dayan Apr 11 '14 at 18:08
  • Absolutely, that's a very good point. I edited the answer explaining the best approach and outlining the possible options. Thanks for the input! – kylealonius Apr 11 '14 at 18:10
  • Thanks so much! I am going to give it a shot right now and I'll post an update! – LadyLuck Apr 11 '14 at 19:06
  • Okay. Thanks for the logout button links....I had already reviewed those and after a few hours of trying, I decided to post on here because I didn't think it was supposed to be hard. Obtaining the exact code for the Logout.asps and the Logout.aspx.cs would be most helpful. I watched the videos but he was using things I'm not (Razor, Msomething 4) so it was confusing. Looked at the JS stuff...doesn't that mean I need to create a .js file? How beginner I am: VERY! Can someone look at the code I have and let me know the simpliest way to get this done by sending exact code references? Thank you! – LadyLuck Apr 11 '14 at 19:30