views:

27

answers:

1

So i've been working on a MVC2 application just to learn the ropes really. One thing i did not like about the default set-up is that the views, models and controllers were in a single assembly together. This was not hard to overcome, moved both to different projects and migrated each folders contents over.

However, now time has come to start fiddling with user roles. I decorate a controller action like so;

    [Authorize(Roles = "Admin"), AcceptVerbs(HttpVerbs.Post)]
    public ActionResult EditProject(Guid Id, FormCollection formValues){}

So here is how my solution is setup;

  • MySolution.Web.Views <-- All aspx / ascx stuff
  • MySolution.Controllers <-- All controllers, including the default AccountController that comes with the MVC2 application

I also have the default 'AccountModel' within the MySolution.Controllers.AccountModels namespace which is where the LogOnModel class is located. Now when i run the program and ask the controller to execute an action which requires a certain role (which i am not) I get the following error;

"Compiler Error Message: CS0234: The type or namespace name 'Models' does not exist in the namespace 'MySolution.Web' (are you missing an assembly reference?)"

It also highlights the following line as the source error;

"public class views_account_logon_aspx : System.Web.Mvc.ViewPage, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler"

and comments the line and file of the error as;

"Source File: c:\Users\\AppData\Local\Temp\Temporary ASP.NET Files\root\d1b48054\1ce7c091\App_Web_logon.aspx.5f83eb8c.mdfplvvy.0.cs"

So I have tried navigating to that file and manually typing in the correct namespace of the LogOnModel but each time i run the project, a new version of this file is created with the incorrect location of LogOnModel reproduced. So clearly there is something within the application that is still looking in the original location for the AccountModel which no longer exists.

I have looked in my web.config file and cannot find anywhere which appears to reference the LogOnModel in the MySolution.Web namespace.

Does anyone know how I might inform the application where the LogOnModel now resides ?

The actual application is failing within the AccountController's LogOn action:

public ActionResult LogOn()
{
   return View(); // Failing here
}

So maybe it's something to do with routing ? I have not touched the default setup of the Global.asax file.

+1  A: 

Have you referenced MySolution.Controllers.AccountModels in your web.config namespace section? Or use the Import directive in your aspx, or give the full name in the page directive ViewPage<MySolution.Controllers.AccountModels.LogOnModel>

Gregoire
"give the full name in the page directive ViewPage<MySolution.Controllers.AccountModels.LogOnModel>" <-- This seems to of solved the issue, thank you. Now there are errors surrounding the failure to find stored procedure: "dbo.aspnet_CheckSchemaVersion" which i imagine is a different kettle of fish.
SomeGuy
@SomeGuy: The db error is really a different kettle of fish: that's your web application trying to find the database that's defaulted in a new ASP.NET MVC application (App_Data/AspNetDB.mdf). Change your connection string in web.config and you'll be up and running.
Tomas Lycken