Skip to content

Instantly share code, notes, and snippets.

@joeriks
Last active December 28, 2015 20:49
Show Gist options
  • Select an option

  • Save joeriks/7560073 to your computer and use it in GitHub Desktop.

Select an option

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.
@* 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>
@* 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>
<?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