0

I have this problem with my ASP.NET web app that when i try to create my login then it wont authenticate the user. I have pin pointed my problem to be in my web.config file:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="Workice" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <authentication mode="Forms">
    <forms loginUrl="~/Login/Login" timeout="2880" />
  </authentication>
  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

The code above is full web.config file. The Database works and validations of user is also perfect so its something in the web.config file.

This is my controller:

[HttpPost]
        public ActionResult Login(Customer customer)
        {
            serviceSiteContext db = new serviceSiteContext();
            var c = new Customer();

            if (ModelState.IsValid)
            {
                if (IsValid(customer.EMail, customer.Pass))
                {

                    using (var context = new serviceSiteContext())
                    {
                        c = context.Customer.Where(cos => cos.EMail == customer.EMail).FirstOrDefault();
                    }
                    FormsAuthentication.SetAuthCookie(c.Username, true);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Log ind data er ikke korrekte.");
                }
            }
            return View(c);
        }
  • Are you getting an error? That seems like it's essential to knowing what the problem is. What authentication provider are you using? – mason Dec 23 '14 at 20:16
  • It looks like you are missing the membership section in the web.config so it may be pulling it from the machine.config file. Have you looked there? – Jerode Dec 23 '14 at 20:16
  • I'm not using any but my guess would be that im trying to use the forms authentification. –  Dec 23 '14 at 20:25
  • The machine.config file is not to find anywhere in the project. –  Dec 23 '14 at 20:30
  • @McBoman it is located in the framework directory. I think Ashley Lee may have the right answer for you to check on. – Jerode Dec 23 '14 at 20:32
  • @McBoman Of course `machine.config` isn't in the project. But it's being used by the project. `machine.config` is common to all .NET programs run on the machine. See [Where Is Machine.Config?](http://stackoverflow.com/questions/2325473). – mason Dec 23 '14 at 20:33

1 Answers1

1

Your authentication node should be inside system.web, like this:

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="~/Login/Login" timeout="2880" />
  </authentication>
</system.web>
Ashley Lee
  • 3,810
  • 1
  • 18
  • 26