user1987927
user1987927

Reputation: 31

VS2012 MVC 4.0 Intranet Project using WebMatrix.WebData Reference fails

I did the following:

Create in VS 2012 a MVC 4.0 Application with the Intranet template, switch WindowsAuthentication on. Project can be started and shows Home page.

Then I added under References WebMatrix.WebData and set Copy Local true.

Starting the Application then returns a 404 Error indicating Requested Url: /login.aspx

Strange, isn't it?

I would like to use SimpleMembership Provider but if I cannot even reference the DLL this doesnt convince me.

Can anyone help me up?

Upvotes: 2

Views: 815

Answers (1)

user1987927
user1987927

Reputation: 31

MVC4 Intranet Project template provides a web.config with:

<authentication mode="Windows" />

For some reason unknown to me, just adding the Microsoft ASP.Net Web Pages 2 Nuget Package to a Web App generated from MVC 4 Intranet Project template changes the routing behaviour of the whole application such that /login.aspx becomes the default routing when no controller/action is specified.

This is the defaultUrl default value defined for forms authentication, see forms-Element definition for details.

The following two bypasses work:

  1. Change Route Map by adding something like

        routes.MapRoute(
            name: "LoginRedirect",
            url: "login.aspx/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    

    into Route table.

  2. Modify web.config to contain

    <authentication mode="Windows">
      <forms loginUrl="~/Home/Index" defaultUrl="~/Home/Index"/>
    </authentication>
    

where the forms element provides the proper start page.

Either works. The latter seems more agreeable to me.

Upvotes: 1

Related Questions