Guest User

Guest User

  • Tech Writer
  • 189
  • 25k

The resource cannot be found.

May 17 2018 1:03 AM
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Controller
  1. using System;    
  2. using System.Collections.Generic;    
  3. using System.Linq;    
  4. using System.Web;    
  5. using System.Web.Mvc;    
  6. using System.Configuration;    
  7. using System.Web.Security;    
  8. using MySql.Data.MySqlClient;    
  9. using NewProject160518.Models;    
  10. namespace NewProject160518.Controllers    
  11. {    
  12.     public class HomeController : Controller    
  13.     {    
  14.         // GET: Home    
  15.         string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;    
  16.         [Authorize]    
  17.         public ActionResult Index()    
  18.         {    
  19.               
  20.             return View();    
  21.         }    
  22.         [HttpGet]    
  23.         public ActionResult UserLogin()    
  24.         {    
  25.             return View();    
  26.         }    
  27.         [HttpPost]    
  28.         public ActionResult UserLogin(userlist userlist)    
  29.         {    
  30.             MySqlDataReader rd;    
  31.             MySqlConnection con = new MySqlConnection(constr);    
  32.             con.Open();    
  33.             string Query = "SELECT * FROM userlist where Emailid='"+userlist.Emailid+"' and Password ='"+ userlist.Password+"'";    
  34.             MySqlCommand cmd = new MySqlCommand(Query, con);    
  35.             rd = cmd.ExecuteReader();    
  36.     
  37.             while (rd.Read())    
  38.             {    
  39.     
  40.     
  41.                 if (rd.HasRows)    
  42.                 {    
  43.                     ViewData["Message"] = "Welcome !! "+userlist.Emailid +"";    
  44.                     return RedirectToAction("index");                                          
  45.                     break;    
  46.                 }    
  47.                 //else    
  48.                 //{    
  49.                 //    Response.Write("<script language='javascript'>alert('Invalid EmailI or Password')</script>");    
  50.                 //}    
  51.             }    
  52.             return View();    
  53.         }    
  54.        [Authorize]    
  55.         [HttpPost]    
  56.         public ActionResult Logout()    
  57.         {    
  58.             FormsAuthentication.SignOut();    
  59.             //return View();    
  60.             return RedirectToAction("UserLogin");    
  61.         }    
  62.     }    
  63. }  
UserLogin.cshtml
  1. @model NewProject160518.Models.userlist    
  2.     
  3. @{    
  4.     ViewBag.Title = "UserLogin";    
  5. }    
  6.     
  7. <h2>User Login</h2>    
  8.     
  9.     
  10. @using (Html.BeginForm())     
  11. {    
  12.     @Html.AntiForgeryToken()    
  13.         
  14.     <div class="form-horizontal">    
  15.          @Html.ValidationSummary(true""new { @class = "text-danger" })    
  16.         <div class="form-group">    
  17.             @Html.LabelFor(model => model.Emailid, htmlAttributes: new { @class = "control-label col-md-2" })    
  18.             <div class="col-md-10">    
  19.                 @Html.EditorFor(model => model.Emailid, new { htmlAttributes = new { @class = "form-control" } })    
  20.                 @Html.ValidationMessageFor(model => model.Emailid, ""new { @class = "text-danger" })    
  21.             </div>    
  22.         </div>    
  23.     
  24.         <div class="form-group">    
  25.             @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })    
  26.             <div class="col-md-10">    
  27.                 @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })    
  28.                 @Html.ValidationMessageFor(model => model.Password, ""new { @class = "text-danger" })    
  29.             </div>    
  30.         </div>    
  31.     
  32.         <div class="form-group">    
  33.             <div class="col-md-offset-2 col-md-10">    
  34.                 <input type="submit" value="Create" class="btn btn-default" />    
  35.             </div>    
  36.         </div>    
  37.     </div>    
  38.    @ViewData["Message"]    
  39. }    
  40.     
  41. <div>    
  42.     @Html.ActionLink("Back to List""Index")    
  43. </div>    
  44.     
  45. <script src="~/Scripts/jquery-1.10.2.min.js"></script>    
  46. <script src="~/Scripts/jquery.validate.min.js"></script>    
  47. <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>    
Index.cshtml
  1. @{    
  2.     ViewBag.Title = "Index";    
  3. }    
  4. <h2>Index</h2>    
  5. Welcome @HttpContext.Current.User.Identity.Name    
  6. @if (Request.IsAuthenticated)    
  7. {    
  8.     using (Html.BeginForm("Logout","Home", FormMethod.Post, new { id="logoutForm"}))    
  9.     {    
  10.         <a href="javascript:document.getElementById('logoutForm').submit()">Logout</a>    
  11.     }    
  12. }

Answers (2)