Try this
protected void Create_Click(object sender, EventArgs e)
{
MembershipCreateStatus createStatus;
MembershipUser newUser = Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus);
switch (createStatus)
{
case MembershipCreateStatus.Success:
CreateAccountResults.Text = "The user account was successfully created!";
break;
case MembershipCreateStatus.DuplicateUserName:
CreateAccountResults.Text = "There already exists a user with this username.";
break;
case MembershipCreateStatus.DuplicateEmail:
CreateAccountResults.Text = "There already exists a user with this email address.";
break;
case MembershipCreateStatus.InvalidEmail:
CreateAccountResults.Text = "There email address you provided in invalid.";
break;
case MembershipCreateStatus.InvalidAnswer:
CreateAccountResults.Text = "There security answer was invalid.";
break;
case MembershipCreateStatus.InvalidPassword:
CreateAccountResults.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";
break;
default:
CreateAccountResults.Text = "There was an unknown error; the user account was NOT created.";
break;
}
}
for more info visit
http://www.asp.net/Learn/Security/tutorial-05-cs.aspx
Good Luck
Friday, July 25, 2008
Method to Get Hijri Date
Try this method:
public static string ConvertDateString(string DATE_INS, int COND)
{
string functionReturnValue = null;
int CurrentDay;
int CurrentMonth;
int CurrentYear;
System.DateTime DateFrom;
DateFrom = Strings.Trim(DATE_INS);
CurrentDay = DateFrom.Day;
CurrentMonth = DateFrom.Month;
CurrentYear = DateFrom.Year;
if (COND == 1)
{
// من هجرى الى ميلادى
System.DateTime ConversionDate = new System.DateTime(CurrentYear, CurrentMonth, CurrentDay, new HijriCalendar());
functionReturnValue = ConversionDate;
}
else if (COND == 2)
{
CultureInfo higri_format = new CultureInfo("ar-SA"); higri_format.DateTimeFormat.Calendar = new HijriCalendar();
System.DateTime CurrentDate;
if (!Information.IsDate(DATE_INS))
{
functionReturnValue = "";
return;
// TODO: might not be correct. Was : Exit Function
}
CurrentDate = Convert.ToDateTime(DATE_INS);
functionReturnValue = CurrentDate.Date.ToString("dd/MM/yyyy", higri_format);
}
return functionReturnValue;
}
Good Luck
public static string ConvertDateString(string DATE_INS, int COND)
{
string functionReturnValue = null;
int CurrentDay;
int CurrentMonth;
int CurrentYear;
System.DateTime DateFrom;
DateFrom = Strings.Trim(DATE_INS);
CurrentDay = DateFrom.Day;
CurrentMonth = DateFrom.Month;
CurrentYear = DateFrom.Year;
if (COND == 1)
{
// من هجرى الى ميلادى
System.DateTime ConversionDate = new System.DateTime(CurrentYear, CurrentMonth, CurrentDay, new HijriCalendar());
functionReturnValue = ConversionDate;
}
else if (COND == 2)
{
CultureInfo higri_format = new CultureInfo("ar-SA"); higri_format.DateTimeFormat.Calendar = new HijriCalendar();
System.DateTime CurrentDate;
if (!Information.IsDate(DATE_INS))
{
functionReturnValue = "";
return;
// TODO: might not be correct. Was : Exit Function
}
CurrentDate = Convert.ToDateTime(DATE_INS);
functionReturnValue = CurrentDate.Date.ToString("dd/MM/yyyy", higri_format);
}
return functionReturnValue;
}
Good Luck
Login Redirection
Try this:
in Login.aspx page
public static void RequestLogin()
{
string OriginalUrl = HttpContext.Current.Request.RawUrl;
string LoginPageUrl = "~/login.aspx";
HttpContext.Current.Response.Redirect(_String.Format("{0}?ReturnUrl={1}", LoginPageUrl, OriginalUrl));
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)Login1.FindControl("UserName");
//MembershipUser user = Membership.GetUser(TextBox1.Text);
MembershipUser user = Membership.GetUser(Login1.UserName);
if (Request.QueryString["ReturnUrl"] != null)
{
Response.Redirect(Request.QueryString["ReturnUrl"].ToString());
}
else
{
//-- check if login user in Admin role
if (Roles.IsUserInRole(TextBox1.Text, "Admin"))
{
Response.Redirect("~/Admin/Default.aspx");
}
//-- check if login user in User role
else if (Roles.IsUserInRole(TextBox1.Text, "User"))
{
Response.Redirect("~/User/Default.aspx");
}
}
}
Good Luck
in Login.aspx page
public static void RequestLogin()
{
string OriginalUrl = HttpContext.Current.Request.RawUrl;
string LoginPageUrl = "~/login.aspx";
HttpContext.Current.Response.Redirect(_String.Format("{0}?ReturnUrl={1}", LoginPageUrl, OriginalUrl));
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)Login1.FindControl("UserName");
//MembershipUser user = Membership.GetUser(TextBox1.Text);
MembershipUser user = Membership.GetUser(Login1.UserName);
if (Request.QueryString["ReturnUrl"] != null)
{
Response.Redirect(Request.QueryString["ReturnUrl"].ToString());
}
else
{
//-- check if login user in Admin role
if (Roles.IsUserInRole(TextBox1.Text, "Admin"))
{
Response.Redirect("~/Admin/Default.aspx");
}
//-- check if login user in User role
else if (Roles.IsUserInRole(TextBox1.Text, "User"))
{
Response.Redirect("~/User/Default.aspx");
}
}
}
Good Luck
Logout
Try this code:
protected void lnkbLogout_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut(); Session.Abandon(); HttpContext.Current.Response.Redirect("Login.aspx", true);
}
//--- another way
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
//FormsAuthentication.SignOut();
//Roles.DeleteCookie();
//Session.Clear();
}
protected void lnkbLogout_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut(); Session.Abandon(); HttpContext.Current.Response.Redirect("Login.aspx", true);
}
//--- another way
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
//FormsAuthentication.SignOut();
//Roles.DeleteCookie();
//Session.Clear();
}
Subscribe to:
Comments (Atom)

