user1071149
user1071149

Reputation: 11

MVC 3 FormsAuthentication Not working when deployed

I have an MVC 3 Application that works fine in my dev environment (you must have heard that before..) I am deploying it to a free hosting service http://somee.com for testing, the .NET framework is set to 4. I have a custom membership provider. I am able to register a user, as I can see it in the database, but the user never gets authenticated. I always get redirected to the LogOn page, either after the registration or when loging on. I have done a bin deployment and have this dlls in my bin folder:

•System.Web.Mvc
•Microsoft.Web.Infrastructure
•System.Web.Razor
•System.Web.WebPages •System.Web.WebPages.Razor
•System.Web.Helpers

In the config: ...

   <add key="loginUrl" value="~/Account/Logon" />
  </appSettings>
....
    <membership defaultProvider="ServiceMembershipProvider">
      <providers>
        <clear/>
        <add name="ServiceMembershipProvider"
             type="Infrastruture.ServiceMembershipProvider, Infrastruture" />
      </providers>
    </membership>
  <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

The controllers:

  [HttpPost]
        public ActionResult Register(FormCollection registration)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var registrationViewModel = MapFormToRegistrationViewModel(registration);
                    companyManager.RegisterCompany(registrationViewModel);
                    FormsAuthentication.SetAuthCookie(registrationViewModel.SystemUserViewModel.Email, false);
                    return RedirectToAction("Welcome", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "LogId already taken");
                }
            }
            catch(Exception ex)
            {
                               return View("Register", new RegistrationViewModel(dataReferenceService));
            }

            return View("Register", new RegistrationViewModel(dataReferenceService));
        }
    /* /Home/Welcome */
    [Authorize]
    public ActionResult Welcome()
    { return View(); }

Running out of ideas now ...

Upvotes: 0

Views: 1732

Answers (1)

Maurice Butler
Maurice Butler

Reputation: 414

I know this is an old question but I had a similar problem and found this while searching for the answer.

The solution is to add the following setting to your web config file.

<appSettings>
<add key="enableSimpleMembership" value="false"/>
</appSettings>

The reason this is required is some pre application startup code appears to have some issues with default settings.

A better explaination and the place I found this solution is here

Upvotes: 2

Related Questions