. NET background for HTML tag button jump background and background simple validation

Source: Internet
Author: User
Tags button type

  

---------------------------------Genius, learn God, Daniel, Hacker please bypass the de split line-----------------------------------------------------------------------

Well, this may be relatively simple, forgive me this weak for the first time to do. NET also looked for long data, so paste out, avoid everyone again detours.

Because the button for HTML is not a server-side control, you have to change the following to jump to the background.

   <button type= "Submit"  runat= "server" onserverclick= "login" > Login </button>    

Code for front desk login.aspx

1<%@ Page language="C #"autoeventwireup="true"codefile="Login.aspx.cs"inherits="Admin_index"%><!--This line remember to change2 3<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">4"en" class="No-js">5 67 8<meta charset="Utf-8">9<title>homepage Background Login </title>Ten<meta name="Viewport"Content="Width=device-width, initial-scale=1.0"> One<meta name="Description"Content=""> A<meta name="author"Content=""> -  -<!--CSS-- the<link rel="stylesheet"href="Assets/css/reset.css"> -<link rel="stylesheet"href="Assets/css/supersized.css"> -<link rel="stylesheet"href="Assets/css/style.css"> -  +<!--HTML5 Shim, forie6-8Support of HTML5 elements-- -<!--[ifLt IE9]> +<script src="Http://html5shim.googlecode.com/svn/trunk/html5.js"></script> A<! [endif]--> at  - -  -<body> -  -<divclass="Page-container"> in -<form id="form"runat="Server"Method="Post"> to<input type="text"Name="username"Placeholder="User name"/> +<input type="Password"Name="Password"Placeholder="Password"/> -<button type="Submit"runat="Server"onserverclick="Login"> Sign in </button> <!----> the<!-- *<asp:button id="Button"runat="Server"text="Login"onclick="Login"/> $                 // -Panax Notoginseng<divclass="Error"><span>+</span></div> -</form> the             +</div> A          the<!--Javascript-- +<script src="Assets/js/jquery-1.8.2.min.js"></script> -<script src="Assets/js/supersized.3.2.7.min.js"></script> $<script src="Assets/js/supersized-init.js"></script> $<script src="Assets/js/scripts.js"></script> -  -</body> the  -

After the foreground is done, it is from the background to the value of the HTML tag, with request.form["username"] according to its Name property to take the value. Then if the user name password is correct then jump to the page and put a value in the session, if not correct, pop-up prompt.

Background Login.aspx.cs Code

1 usingSystem;2 usingSystem.Collections.Generic;3 usingsystem.web;4 usingSystem.Web.Security;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 8  Public Partial classAdmin_index:System.Web.UI.Page9 {Ten     protected voidPage_Load (Objectsender, EventArgs e) One     { A  -     } -     protected voidLogin (Objectsender, EventArgs e) the     { -         if(request.form["username"] =="123456"&& request.form["Password"] =="123456") -         { -              +             //formsauthentication.redirectfromloginpage (user, true);//using the security mechanism of. NET -session["Login"] ="OK"; Randomly put a value in the session +Response.Redirect ("~/admin/paper.aspx"); A             at         } -         Else -         { -Response.Write ("<script>alert (' Please enter the correct user and password! ');</script>"); -         } -  in  -     } to}

Down to do the background verification, that is, if you are not logged in can not do related operations.

Background Honor.asp.cs code (login after a casual page of the background)

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 8  Public Partial classHonor:System.Web.UI.Page9 {Ten     protected voidPage_Load (Objectsender, EventArgs e) One     { A         if(session["Login"] ==NULL|| session["Login"]. ToString () = =""&& session["Login"]. ToString ()! ="OK") -         { -  theResponse.Write ("<script>alert (' No login, please login '); window.top.location.href= '/login.aspx ';</script>"); -  -  -         } +  -     } +}

The above determines whether the user is logged in by judging the value in the session.

This verification method is relatively simple, originally the landlord wants to use the security mechanism of. NET, but will not, will have to use this, so there will be students can teach me a bit haha!

. NET background for HTML tag button jump background and background simple validation

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.