Hello, I have LogOn.ascx control which is located on master page site.master:
<% Html.RenderPartial("LogOn"); %>
This control contains form with email and password textboxed which is submitted to LoginController:
public class LoginController : Controller
{
...
[HttpPost]
public ActionResult Login(string email, string password)
{
if (this.userRepository.ExistByEmail(email) &&
this.authenticationService.IsPasswordMatches(email, password))
{
var user = this.userRepository.GetByEmail(email);
this.userSession.LogIn(user);
return PartialView("LogOn", user);
}
return PartialView("LogOn");
}
}
So if user is successfully authenticated I pass user into model of LogOn partial view (simplified):
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Core.Model.User>" %>
<%= this.Model.FirstName %>
I have 2 problems with this code:
After calling
return PartialView("LogOn")
I get exception "The IControllerFactory 'UI.Services.ControllerFactory' did not return a controller for the name 'default.aspx'" This issue is solved by adding routing for "default.aspx". But why request goes to "default.aspx" when I callreturn PartialView(..)
? (I'm using VS web server)I get null reference exception inside LogOn.ascx even if user was successfully authenticated and non-null value was passed into PartialView on the following line:
<%= this.Model.FirstName %>
Does anybody have an idea why user is not passed into LogOn.ascx? Thanks