MVC Request Processing Response "User Login"

Source: Internet
Author: User

MVC Routing Settings App_start/routeconfig.cs

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using System.web.routing;namespace mvclogin{public    class Routeconfig    {public        static void RegisterRoutes ( RouteCollection routes)        {            routes. Ignoreroute ("{resource}.axd/{*pathinfo}");            Routes. MapRoute (                name: "Default",                URL: "{controller}/{action}",                defaults:new {controller = "Login", action = " Index "}            );}}}    


Controller Controllers/logincontroller.cs

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using        System.data;using system.data.sqlclient;namespace mvclogin.controllers{public class Logincontroller:controller {        GET:/login/public actionresult Index () {return View (); } public ActionResult Add () {String Name = request["UserName"].            ToString (); String Pass = request["Password"].            ToString ();            String sql = "INSERT into T_login values (@userName, @pass)";            int i = sqlhelper.executenonquery (sql, New SqlParameter ("UserName", Name), New SqlParameter ("Pass", pass));        Return Content ("OK");        Public ActionResult Login () {return View ("login"); Public ActionResult Loginresponse () {String Name = request.form["UserName"].            ToString (); String Pass = request.form["Password"].         ToString ();   String sql = "SELECT * from T_login where [email protected]";            DataTable dt = sqlhelper.executedatatable (sql, New SqlParameter ("name", name)); if (dt.                Rows.Count <= 0) {viewdata["Message"] = "user name does not exist";            Return View ("Login"); } if (dt.                Rows.Count > 1) {viewdata["Message"] = "big thing is not good, query out more than one data";            Return View ("Login"); } if (dt. rows[0]["Password"].                ToString () = Pass) {viewdata["Message"] = "wrong password";            Return View ("Login");        } return Content ("Congratulations ~ landing success"); }    }}


View

Index View Views/login/index.aspx

<%@ page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%><! DOCTYPE html>

Login View Views/login/login.aspx

<%@ page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%><!    DOCTYPE html>




MVC Request Processing Response "User Login"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.