Daftar dan Masuk di MVC

pemrograman

[ad_1]

INILAH KELAS TABEL SAYA DI 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; }
       
   }

DAN KELAS BARU UNTUK CREATWE RememberMe FIELD

C#
public class SetLogin
  {
      public string UserName { get; set; }
      public string Password { get; set; }
      public bool RememberMe { get; set; }
  }

HALAMAN MULAI ATAU HALAMAN UTAMA INI

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>

HALAMAN MASUK INI

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>

DAN TINDAKAN

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");
       }

TAPI…saat saya login ke database tapi tidak berfungsi saat kembali ke halaman utama…
tidak bekerja

HTML
@if( Request.IsAuthenticated)
        {
        @:<p>Welcome,@User.Identity.Name</p>
        @Html.ActionLink("خروج", "Logout")
        }
        else{
       @Html.ActionLink("ورود", "login")

       @Html.ActionLink("ثبت نام", "GetUser")
        }
      </div>

Solusi 1

tolong bantu aku, aku ingin bantuan :'(

[ad_2]

コメント

タイトルとURLをコピーしました