Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem With "if" Statement Flow Asp.net

Posted on 2009-06-29
5
Medium Priority
?
220 Views
Last Modified: 2012-05-07
I have stored subscription expiration dates in a field inside my db. The dates are either 31 days after the date purchased or 1 day after the date purchased. When going to use these dates I am uncertain how to create an "if" statement that makes sure the user cannot login after his expiration date. Below I have only a piece of it that could be user for users who have an expiration date of tomorrow. Can someone add on to this to not let users login if they are past their 31 day subscription? Also is this "if" suppose to go into the Login_click event to work corectly or am I putting it in the wrong place?
//For case user has only 1 day subscription
  if (SubExpirationDate.Date != DateTime.Now.Date)
        {
            Response.Write("Expired");
        }

Open in new window

0
Comment
Question by:npl77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:urir10
ID: 24740133
Are you storing their expiration date in the database or just the number 31 / 1?
And yes the if can go in the login click even which you will redirect in case its expired.
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 24740149
your logic is off.
it should be:
if (SubExpirationDate.Date > DateTime.Now.Date)
        {
//would do Repsonse.Redirect(Aspired.aspx.)
           Response.Write("Expired");
        }
else
Response.Redirect("~/members/home.aspx")

or something to that effect.
0
 

Author Comment

by:npl77
ID: 24740299
Ok, how can I use the login control in asp.net to redirect to a PurchasedPage if the user has logged in successfully and fullfilled the expirationdate? Also I am not sure how/where to set Failure.Text messages stating to the user either his subscription has expired or he has an invalid password. Here is what I have so far Can someone help me fix this thing to work as stated?

The could maybe wrong and definatly not complete(I dont know where to put the invalid password fail text, also am not sure I am using the right event)

One other thing I have put this in my web config...forgot what it was for dunno if it effects this code or not....
<forms name="BMHLogin" loginUrl="Login.aspx" path="/" protection="All" timeout="60" defaultUrl="Purchased.aspx">
</forms>
protected void LoginButton_Click(object sender, EventArgs e)
    {
 
        DataTable dt = BMHAccess.GetUserInfo(login2.UserName);
        if (dt.Rows.Count > 0)
        {
          DateTime exDate=DateTime.Parse(dt.Rows[0]["SubExpirationDate"].ToString());
            if (exDate > DateTime.Now.Date)
        {
          //would do Repsonse.Redirect(Aspired.aspx.)
            Response.Redirect("PurchasedPage.aspx");
           
        }
 
 
            
        }
        else
        {
            login2.FailureText = "Expired";
        
        }
}

Open in new window

0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24740639
You should use OnAuthenticate event of Login control and not LoginButton OnClick.

protected void login2_Authenticate(object sender, AuthenticateEventArgs e)
    {
if(Membership.ValidateUser(login2.UserName,login2.Password))
{ //user is authenticated
  DataTable dt = BMHAccess.GetUserInfo(login2.UserName);
        if (dt.Rows.Count > 0)
        {
          DateTime exDate=DateTime.Parse(dt.Rows[0]["SubExpirationDate"].ToString());
            if (exDate.Date > DateTime.Now.Date)
        {      //valid subscription
                e.Authenticated = true;
                 Response.Redirect("PurchasedPage.aspx");          
        }
     else
        {   //Subscription Expired
            login2.FailureText = "Subscription Expired";
            Response.Redirect("Subscribe.aspx");
        }
}
//this else is not mandatory it can be removed
else
{   //Invalid username/password
    e.Authenticated = false;
}
}
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24740654
may be i missed one }
protected void login2_Authenticate(object sender, AuthenticateEventArgs e)
    {
if(Membership.ValidateUser(login2.UserName,login2.Password))
{ //user is authenticated
  DataTable dt = BMHAccess.GetUserInfo(login2.UserName);
        if (dt.Rows.Count > 0)
        {
          DateTime exDate=DateTime.Parse(dt.Rows[0]["SubExpirationDate"].ToString());
            if (exDate.Date > DateTime.Now.Date)
        {      //valid subscription
                e.Authenticated = true;
                 Response.Redirect("PurchasedPage.aspx");          
        }
     else
        {   //Subscription Expired
            login2.FailureText = "Subscription Expired";
            Response.Redirect("Subscribe.aspx");
        }
}
}
//this else is not mandatory it can be removed
else
{   //Invalid username/password
    e.Authenticated = false;
}
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question