Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
THIS IS MY TABLE CLAS IN DATABASE
C#
public partial class tblUser
   {
       public int Id { get; set; }
       public string Name { get; set; }
       public string Lname { get; set; }
       public string UserName { get; set; }
       public string Password { get; set; }
       public string Email { get; set; }
       public string Address { get; set; }
       public string City { get; set; }
       public string Mobile { get; set; }
       public string Tell { get; set; }
       public System.DateTime? InsertDate { get; set; }
       
   }

AND NEW CLASS FOR CREATWE RememberMe FIELD
C#
public class SetLogin
  {
      public string UserName { get; set; }
      public string Password { get; set; }
      public bool RememberMe { get; set; }
  }


THIS START PAGE OR MAIN PAGE
HTML
<div style="float: right">
             
         @if( Request.IsAuthenticated)
         {
         @:<p>Welcome,@User.Identity.Name</p>
         @Html.ActionLink("خروج", "Logout")
         }
         else{
        @Html.ActionLink("ورود", "login")  
          
        @Html.ActionLink("ثبت نام", "GetUser")
         }
       </div>

THIS LOGIN PAGE
HTML
<div class="editor-label">
               @Html.Label("نام کاربری")
       </div>
       <div class="editor-field">
           @Html.EditorFor(model => model.UserName)
           @Html.ValidationMessageFor(model => model.UserName)
       </div>
 
       <div class="editor-label">
               @Html.Label("رمز ورود")
       </div>
       <div class="editor-field">
           @Html.EditorFor(model => model.Password)
           @Html.ValidationMessageFor(model => model.Password)
       </div>
      <div class="editor-label">
               @Html.Label("رمز ورود")
       </div>
       <div class="editor-field">
           @Html.CheckBoxFor(model => model.RememberMe)
           @Html.Label("مرا به خاطر بسپار")
           @*@Html.ValidationMessageFor(model => model.Password)*@
       </div>

AND ACTION

C#
[HttpGet]
       public ActionResult login()
       {
           return View();
       }
       [HttpPost]
       public ActionResult login(Models.SetLogin user)
       {
           if (ModelState.IsValid)
           {
              Models.ToranjEntities db = new Models.ToranjEntities();
               var query= from f in db.tblUser
                         where f.UserName==user.UserName && f.Password==user.Password
                         select f.UserName; 
               if (query==null)
               {
                   ModelState.AddModelError("", "Login data is incorrect!");              
               }
               else
               {
                   FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
                   return RedirectToAction("MainView", "Home");
               }
           }
           return View(user);
       }
 
       public ActionResult Logout()
       {
           FormsAuthentication.SignOut();
           return RedirectToAction("MainView", "Home");
       }


BUT ... when i login to database but dont work when back to main page ...
not work
HTML
@if( Request.IsAuthenticated)
        {
        @:<p>Welcome,@User.Identity.Name</p>
        @Html.ActionLink("خروج", "Logout")
        }
        else{
       @Html.ActionLink("ورود", "login")

       @Html.ActionLink("ثبت نام", "GetUser")
        }
      </div>
Posted
Comments
JoCodes 14-Oct-13 11:44am    
Whats the error you are getting? Or your user is not able to login as an authorize user?
JoCodes 14-Oct-13 13:44pm    
please dont add comments in the solution space

1 solution

plese help me i want help :'(
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900