Sk Jha

Sk Jha

  • NA
  • 113
  • 41.5k

action method not found after post the login form in iis

May 4 2020 8:31 PM

Help me to resolve this issue. after publish on IIS server action method not found while we submit the login form. It's working with when executing on visual studio.

this is the view "Index.cshtml"
  1. <form method="post" action="/Reception/Login/Index">  
  2.                         <div asp-validation-summary="ModelOnly" class="text-danger"></div>  
  3.                         <div class="form-group">  
  4.                             <label asp-for="UserName" class="control-label">User Name</label>  
  5.                             <input asp-for="UserName" class="form-control" />  
  6.                             <span asp-validation-for="UserName" class="text-danger"></span>  
  7.                         </div>  
  8.                         <div class="form-group">  
  9.                             <label asp-for="Password" class="control-label">Password</label>  
  10.                             <input asp-for="Password" class="form-control" type="password" />  
  11.                             <span asp-validation-for="Password" class="text-danger"></span>  
  12.                         </div>  
  13.   
  14.                         <div class="form-group">  
  15.                             <input type="submit" value="Create" class="btn blue-gradient" />  
  16.                         </div>  
  17.                     </form>  
this is controller "LoginController"
 
  1. namespace DeltaSoftLIS.Controllers  
  2. {  
  3. [Area("Reception")]  
  4. public class LoginController : Controller  
  5. {  
  6.     private readonly ApplicationDbContext _db;  
  7.   
  8.     public LoginController(ApplicationDbContext context)  
  9.     {  
  10.         _db = context;  
  11.     }  
  12.     public IActionResult Index()  
  13.     {  
  14.         return View();  
  15.     }  
  16.   
  17.   
  18.     [HttpPost]  
  19.     //[Route("/Reception/Login/Index/{username?}/{password}")]  
  20.     public IActionResult Index(string ? username, string ? password)  
  21.     {  
  22.   
  23.         var userId = _db.logins.Where(p=>p.UserName==username && p.Password==password && p.ExpiryDate> DateTime.Now).Select(p=>p.Id).FirstOrDefault();  
  24.         if (userId>0)  
  25.         {  
  26.             HttpContext.Session.SetString("username", username);  
  27.             return Redirect("~/Reception/Home/Index");  
  28.         }  
  29.         else  
  30.         {  
  31.             ViewBag.error = "Invalid Login..!";  
  32.             return View("Index");  
  33.         }  
  34.     }  
  35.   
  36.     [HttpGet]  
  37.     public IActionResult Logout()  
  38.     {  
  39.         HttpContext.Session.Remove("username");  
  40.         return RedirectToAction("Index");  
  41.     }  
  42.   }  
  43.  }  
Kindly help me to resolve this issue. I am stuck here 

Answers (2)