So I followed the post and have created template/members and protected a page. When I try to view the page I'm presented with the login page, so far so good. After I enter my username / password the login page simply reloads and does not display the protected content.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Security; using Umbraco.Web.Mvc;
namespace W3S.Controllers { public class LoginController : SurfaceController { // // GET: /Login/ public ActionResult Login() { MembershipUser msUser = Membership.GetUser(); if (msUser != null) { ViewBag.Username = msUser.UserName; } return View(); } [HttpPost] public ActionResult Login(String username, String password) { MembershipUser msUser = Membership.GetUser(); if (msUser == null) { if (Membership.ValidateUser(username, password)) { FormsAuthentication.SetAuthCookie(username, true); Response.Redirect("/"); } else { ViewBag.LoginError = "no user found!"; } } else { ViewBag.Username = msUser.UserName;
Members / Login
Hi,
I have a basic site and would like to password protect it. I tried Razor login but didnt get anywhere with it sadly.
I'm trying to use the http://www.mortenbock.dk/blog/2009/04/01/setting-up-membership-in-umbraco.aspx solution which seems to be working for a lot of people.
So I followed the post and have created template/members and protected a page. When I try to view the page I'm presented with the login page, so far so good. After I enter my username / password the login page simply reloads and does not display the protected content.
Would appreciate any suggestions....
Sami
I just make a child action like this:
@{
Layout = null;
}
<form method="post">
@if (!String.IsNullOrEmpty(ViewBag.LoginError)) {
<div style="color:red">@ViewBag.LoginError</div>
}
@if(String.IsNullOrEmpty(ViewBag.Username)){
<div><label for="name">Username:</label>
<input type="text" id="username" name="username"/></div>
<div><label for="password">Password:</label>
<input type="password" id="password" name="password"/></div>
<div><input type="submit" id="submit" name="submit" value="login"/></div>
} else {
@ViewBag.Username
<input type="submit" id="submit" name="submit" value="logout"/>
}
</form>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Umbraco.Web.Mvc;
namespace W3S.Controllers
{
public class LoginController : SurfaceController
{
//
// GET: /Login/
public ActionResult Login() {
MembershipUser msUser = Membership.GetUser();
if (msUser != null) {
ViewBag.Username = msUser.UserName;
}
return View();
}
[HttpPost]
public ActionResult Login(String username, String password) {
MembershipUser msUser = Membership.GetUser();
if (msUser == null) {
if (Membership.ValidateUser(username, password)) {
FormsAuthentication.SetAuthCookie(username, true);
Response.Redirect("/");
} else {
ViewBag.LoginError = "no user found!";
}
} else {
ViewBag.Username = msUser.UserName;
if (Request["submit"] == "logout") {
FormsAuthentication.SignOut();
Response.Redirect("/");
}
}
return View();
}
}
}
Thank you very much for your reply. How should I use this (sorry, im not a web developer) to allow access to the site ?
If you're no developer then it's not so easy to build.. sorry don't know any module for it because it's so easy to develop for me!
Perhaps you could point me in the right direction ? Not a developer; have plenty enthusiasm.
I write Umbraco code in a real developer way, it's not really possible to do it in a little post on a forum :)
is working on a reply...