Last active
December 28, 2015 20:49
-
-
Save joeriks/7560073 to your computer and use it in GitHub Desktop.
The most basic (clear text, database free) type of authentication for an asp.net site, using Razor syntax. All .cshtml pages will be protected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @* needs to be in the root (this makes asp net setup cshtml file type automatically) *@ | |
| @* this file and all .cshtml files (other than login) is protected *@ | |
| <html> | |
| <body> | |
| Welcome authenticated user | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @* needs to be saved in the /account folder *@ | |
| @{ | |
| if (FormsAuthentication.Authenticate (Request["username"], Request["password"])){ | |
| FormsAuthentication.RedirectFromLoginPage (Request["username"], false);} | |
| } | |
| <html> | |
| <body> | |
| <form method="post"> | |
| <input type="text" name="username" placeholder="username" /> | |
| <input type="password" name="password" placeholder="password" /> | |
| <input type="submit"/> | |
| </form> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <configuration> | |
| <system.web> | |
| <compilation debug="false" targetFramework="4.0" /> | |
| <authentication mode="Forms"> | |
| <forms> | |
| <credentials passwordFormat="Clear"> | |
| <user name="myusername" password="mypassword" /> | |
| </credentials> | |
| </forms> | |
| </authentication> | |
| <authorization> | |
| <deny users="?" /> | |
| </authorization> | |
| </system.web> | |
| </configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment