I'm new to Umbraco and MVC in general and I'm currently crawling the web for examples on how to setup certain things. For now, I got a basic page running and also collected some experience with SurfaceControllers and Models. Now I'm trying to integrate a Member Login for a multi-site scenario:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace WebFrontend.Models
{
public class MemberLoginModel
{
[Display(Name = "Username")]
[Required(ErrorMessage = "Please enter an username.")]
public string Username { get; set; }
[Display(Name = "Password")]
[Required(ErrorMessage ="Please enter a password.")]
[DataType(DataType.Password)]
public string Password { get; set; }
[Display(Name = "RememberMe")]
public bool RememberMe { get; set; }
[Display(Name = "RedirectUrl")]
public string RedirectUrl { get; set; }
}
}
And the corresponding surface controler:
using WebFrontend.Models;
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 WebFrontend.Controllers
{
public class MemberController : SurfaceController
{
public ActionResult RenderLogin()
{
return PartialView("Members/_MemberLogin", new MemberLoginModel());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SubmitLogin(MemberLoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
var myUser = System.Web.Security.Membership.GetUser(model.Username);
if (myUser != null)
{
returnUrl = myUser.Comment;
}
UrlHelper myHelper = new UrlHelper(HttpContext.Request.RequestContext);
if (myHelper.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return Redirect("/c500_portal/");
}
}
else
{
ModelState.AddModelError("", "The username or password provided is incorrect.");
}
}
return CurrentUmbracoPage();
}
public ActionResult RenderLogout()
{
return PartialView("Members/_MemberLogout", null);
}
public ActionResult SubmitLogout()
{
TempData.Clear();
Session.Clear();
FormsAuthentication.SignOut();
return Redirect("/portallogin/");
}
}
}
I got now deeper into debugging and tried also with the standard Macros provided for Login / Status:
The login is working without any error (in my code Members.Login(model.Username, model.Password) results in TRUE and the cookies are created), but if I go to the status page and do a @loginStatusModel.IsLoggedIn, I get a FALSE
Umbraco Version is 8.13 and I already did an 'Update-Package UmbracoCMS -Reinstall -Safe'
I went through all installed packages and found out, that the Nuget UmbracoIdentity was installed on an early version to integrate MS Authentication but no configuration was done. (Member Properties, as suggested on the git page) So I assumed, that this package leads to a misbehavior with the standard login and removed it.
This broke my site with:
The following errors occurred while attempting to load the app.
- The OwinStartupAttribute.FriendlyName value 'UmbracoDefaultOwinStartup' does not match the given value 'UmbracoIdentityStartup' in Assembly
I fixed this by replacing "UmbracoIdentityStartup" in the Web.config appSettings with:
The issue was the NuGet Package UmbracoIdentity. As soon as you install this package, classical Umbraco Identity Provider is broken and uninstalling does not fix the issue. I ended up first starting to customize UmbracoIdentity to fit my layout but with every update I have to merge the customizations.
Now I started over with a complete and fresh reinstall of Umbraco and transfered all my custom code again. Now its working flawlessly.
Lessons learned:
If you want to use 3rd party auth with UmbracoIdentity, you have to use this solution for the whole Login procedure as soon as its installed. Make sure to follow also the installation instructions on the git page
If you don't want to use this, never install it or it gets messsy (uninstall is nor working properly and Umbraco gets broken)
Also the NuGet MembersListView is making problems with the Umbraco Version I have installed (8.13), I didn't dig deeper in this.
Glad if this helps anyone struggling with the same issues than I did :)
Occured Error (Messages):
Login not working, login page is always reloading, LoggedIn Status is false
UmbracoIdentity Uninstall Error:
The following errors occurred while attempting to load the app. - The OwinStartupAttribute.FriendlyName value 'UmbracoDefaultOwinStartup' does not match the given value 'UmbracoIdentityStartup' in Assembly
Umbraco complained about a lot of missing libraries after installing MembersListView NuGet
Member Login not working properly, login is just refreshed (codeshare example)
Dear Umbraco community
I'm new to Umbraco and MVC in general and I'm currently crawling the web for examples on how to setup certain things. For now, I got a basic page running and also collected some experience with SurfaceControllers and Models. Now I'm trying to integrate a Member Login for a multi-site scenario:
I started with the example from Paul Seal: https://codeshare.co.uk/blog/tutorial-how-to-create-member-login-and-logout-form-in-umbraco-mvc/
My current model:
And the corresponding surface controler:
And the partial view for the login page:
When I enter the correct username and password, the login page is simply refreshed, nothing else happens.
Can anyone please point me in the right direction ;)
Thanks and have a good day! Chris
from web.config comment:
Additional information:
Stackoverflow: MVC 5 disabling Formsauthentication
Even with this fix, as soon as I re-enable the Site protection, it's repeating the login page after the redirect.
Current Controller part looks like this:
Members.Login() returns true but access to the restricted page is still not granted (login is reloading)
I got now deeper into debugging and tried also with the standard Macros provided for Login / Status:
The login is working without any error (in my code Members.Login(model.Username, model.Password) results in TRUE and the cookies are created), but if I go to the status page and do a @loginStatusModel.IsLoggedIn, I get a FALSE
Umbraco Version is 8.13 and I already did an 'Update-Package UmbracoCMS -Reinstall -Safe'
Few hours later... :)
I went through all installed packages and found out, that the Nuget UmbracoIdentity was installed on an early version to integrate MS Authentication but no configuration was done. (Member Properties, as suggested on the git page) So I assumed, that this package leads to a misbehavior with the standard login and removed it.
This broke my site with:
I fixed this by replacing "UmbracoIdentityStartup" in the Web.config appSettings with:
But the login is still not working.
The issue was the NuGet Package UmbracoIdentity. As soon as you install this package, classical Umbraco Identity Provider is broken and uninstalling does not fix the issue. I ended up first starting to customize UmbracoIdentity to fit my layout but with every update I have to merge the customizations.
Now I started over with a complete and fresh reinstall of Umbraco and transfered all my custom code again. Now its working flawlessly.
Lessons learned:
If you want to use 3rd party auth with UmbracoIdentity, you have to use this solution for the whole Login procedure as soon as its installed. Make sure to follow also the installation instructions on the git page
If you don't want to use this, never install it or it gets messsy (uninstall is nor working properly and Umbraco gets broken)
Also the NuGet MembersListView is making problems with the Umbraco Version I have installed (8.13), I didn't dig deeper in this.
Glad if this helps anyone struggling with the same issues than I did :)
Occured Error (Messages):
Login not working, login page is always reloading, LoggedIn Status is false
UmbracoIdentity Uninstall Error:
The following errors occurred while attempting to load the app. - The OwinStartupAttribute.FriendlyName value 'UmbracoDefaultOwinStartup' does not match the given value 'UmbracoIdentityStartup' in Assembly
Umbraco complained about a lot of missing libraries after installing MembersListView NuGet
is working on a reply...