2 asp.net mvc sites conflicting with each other - asp.net-mvc

i have deployed an asp.net mvc site a few days ago and everything is going fine. I just deployed a second website (totally unrelated)
i just went to the first website and i am now getting an error below. Can anyone help me determine what is going on. I dont understand why they would know anything about each other.
The controller name 'Home' is ambiguous between the following types:
Site.netmvc.Controllers.HomeController
SalemGolf.Controllers.HomeController
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The controller name 'Home' is ambiguous between the following types:
Site.netmvc.Controllers.HomeController
SalemGolf.Controllers.HomeController
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The controller name 'Home' is ambiguous between the following types:
Site.netmvc.Controllers.HomeController
SalemGolf.Controllers.HomeController]
System.Web.Mvc.DefaultControllerFactory.GetControllerTypeWithinNamespaces(String controllerName, HashSet`1 namespaces) +417
System.Web.Mvc.DefaultControllerFactory.GetControllerType(String controllerName) +286
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +57
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase h

Make sure you don't have the assembly of the other site in your Bin directory.

Related

ASP.NET MVC 5 : constructor error 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'

Server Error in '/' Application.
None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'PurchaseModule.Controllers.PurchaseController' can be invoked with the available services and parameters:
Cannot resolve parameter 'PurchaseModule.Repository.IPurchaseRepository purchaseRepo' of constructor 'Void .ctor(PurchaseModule.Repository.IPurchaseRepository, Repository.IRepository.IEmployeeCardRepository,Repository.IRepository.IDimensionRepository, Repository.IRepository.IDimensionValuesRepository, PurchaseModule.Repository.IRequestMarketRepository, PurchaseModule.Repository.IServiceMappingRepository, PurchaseModule.Repository.IFixedAssetsRepository, PurchaseModule.Repository.IPurchaseItemRepository, Repository.IRepository.IWorkflowEntriesRepository, Repository.IRepository.IWorkflowDefinitionRepository, Repository.IRepository.IWorkflowRepository, Repository.IRepository.IPositionRepository, Repository.IRepository.IEmployeeClassesRepository, Repository.IRepository.IGeneralLedgerSetupRepository, Repository.IRepository.IPayrollReportRepository, Repository.IRepository.IEmployerRepository)'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'PurchaseModule.Controllers.PurchaseController' can be invoked with the available services and parameters:
Cannot resolve parameter 'PurchaseModule.Repository.IPurchaseRepository purchaseRepo' of constructor 'Void .ctor(PurchaseModule.Repository.IPurchaseRepository, Repository.IRepository.IEmployeeCardRepository, Repository.IRepository.IDimensionRepository, Repository.IRepository.IDimensionValuesRepository, PurchaseModule.Repository.IRequestMarketRepository, PurchaseModule.Repository.IServiceMappingRepository, PurchaseModule.Repository.IFixedAssetsRepository, PurchaseModule.Repository.IPurchaseItemRepository, Repository.IRepository.IWorkflowEntriesRepository, Repository.IRepository.IWorkflowDefinitionRepository, Repository.IRepository.IWorkflowRepository, Repository.IRepository.IPositionRepository, Repository.IRepository.IEmployeeClassesRepository, Repository.IRepository.IGeneralLedgerSetupRepository, Repository.IRepository.IPayrollReportRepository, Repository.IRepository.IEmployerRepository)'.
This is my code:
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
builder.RegisterType(typeof(PurchaseAdapter)).As(typeof(IPurchaseAdapter)).InstancePerLifetimeScope();
builder.RegisterType(typeof(FixedAssetsAdapter)).As(typeof(IFixedAssetsAdapter)).InstancePerLifetimeScope();
builder.RegisterType(typeof(PurchaseItemAdapter)).As(typeof(IPurchaseItemAdapter)).InstancePerLifetimeScope();
builder.RegisterType(typeof(ServiceMappingAdapter)).As(typeof(IServiceMappingAdapter)).InstancePerLifetimeScope();
builder.RegisterType(typeof(RequestMarketAdapter)).As(typeof(IRequestMarketAdapter)).InstancePerLifetimeScope();
}
I don't understand why I get this error. All of them are showing correctly but I can't enter the page. Does anyone have any ideas?
Cannot resolve parameter 'PurchaseModule.Repository.IPurchaseRepository purchaseRepo'
None of the types registered in your ContainerBuilder are registered as the IPurchaseRepository interface.
You need to register all of the services you use in your DI container.

WebSecurity.InitializeDatabaseConnection method can be called only once

I'm trying Windows Azure to host an MVC4 web application.
I've created a test app, using VS2012 MVC4 internet application template and added a custom Model and Controller to it.
I've published it on Azure and managed to get 'update-database' apply migrations to the Azure Database.
When i try the app locally, but using the Azure SQL database, it works fine.
I can login/register and use my test controller.
When i try the app online, i can use the test controller but login or register links give the following exception:
Server Error in '/' Application.
The "WebSecurity.InitializeDatabaseConnection" method can be called only once.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The "WebSecurity.InitializeDatabaseConnection" method can be called only once.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The "WebSecurity.InitializeDatabaseConnection" method can be called only once.]
WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +123
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +52
MembershipTest2.Filters.SimpleMembershipInitializer..ctor() +193
Do you have any idea where that comes from ?
If i debug (the local version), this method is only called once.
Thanks.
You could try encapsulating the call(s) to that method to ensure it's not called more then once
if (!WebMatrix.WebData.WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection(...);
}
in my case I had both
(in web.config)
<add key="enableSimpleMembership" value="true" />
and
(in _ViewStart.cshtml)
WebSecurity.InitializeDatabaseConnection("club", "Account", "UserID", "UserName", autoCreateTables: true);
Solution: it seems you cannot have both, so remove one
Does the following SO discussion help you?
Cannot seed Users & Roles
I did find the following article helped me lot to use newer MVC4 & EF together with Simple Membership Provider so if you haven't read it please take a look:
SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates

Controller other than Home will not pass MvcIntegrationTesting tests

I am using an adaptation of Steve Sanderson's wonderful MVC Integration Testing Framework.
If I take any view in my application and serve it through this framework (which basically creates a 'fake' worker request through HttpRuntime.ProcessRequest()) I can host it within the ASP.NET Runtime in the context of my integration test.
My question is why would any view from the HomeController go nicely through this process but any other controller give a response with
Path 'get' is forbidden
I can move any view to the HomeController and test it without issue. I see no difference (url not withstanding) of the worker request fake between the two calls. I am at a loss!
Stack trace in test output:
ContentControllerTwitterReturnsTheTwitterView :
FailedSystem.NullReferenceException : Object reference not set to an
instance of an object.
Server stack trace: at
website.tests.ContentControllerTwitterTests.b__0(BrowsingSession
session) at
MvcIntegrationTestFramework.Hosting.AppDomainProxy.RunBrowsingSessionInAppDomain(SerializableDelegate`1
script) in AppDomainProxy.cs: line 19 at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs) at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(ref
MessageData msgData, Int32 type) at
MvcIntegrationTestFramework.Hosting.AppDomainProxy.RunBrowsingSessionInAppDomain(SerializableDelegate1
script) at MvcIntegrationTestFramework.Hosting.AppHost.Start(Action1
testScript) in AppHost.cs: line 34 at
website.tests.ContentControllerTwitterTests.ContentControllerTwitterReturnsTheTwitterView()
in HomeControllerTwitterTests.cs: line 25
Problem was naming ... answer is
Do not name your controllers with same name as a folder within solution!
Old fool :)

Why do I get a Lightbox MVC razor error?

I'm trying to display an image using Lightbox with the logic something like this:
public ActionResult displayImg()
string lbx = "";
return View (lbx);
But it gives an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
You're passing <a ...></a> as a view name, which is translated into a filename in your project.
That's not a valid filename.
You probably want to return Content(...), which returns a literal string.
You also need to map the path using the URL class.

ASP.NET MVC / Castle Windsor / IIS6 / Modified MapRoute {controller}.aspx

I've written a web application with ASP.NET MVC. The default ControllerFactory has been replaced with Castle Windsor's Controller
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
The problem is that I'm using shared hosting which runs II6 so in order to get the MVC working I've had to replace the default MapRoute with
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
[ NOTE THE: {controller}.aspx ]
When I upload a newly created "ASP.NET MVC Web Application" with this modified MapRoute it works fine ... but when I upload my MVC Web Application (that uses the Castle Windsor)
I get the following error in my browser:
URL[ http://10.0.0.9/LoseOnlyToday/Home.aspx ]
Server Error in '/LoseOnlyToday' Application.
The IControllerFactory 'WebUI.WindsorControllerFactory' did not return a controller for a controller named 'Home.aspx'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The IControllerFactory 'WebUI.WindsorControllerFactory' did not return a controller for a controller named 'Home.aspx'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The IControllerFactory 'WebUI.WindsorControllerFactory' did not return a controller for a controller named 'Home.aspx'.]
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +304
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
I assume Castle Windsor does not like interpreting "Home.aspx" as the controller ...
How can I fix this ?
Ok so I found out why its not working ... when you I uploaded the website files originally I uploaded everything - but after making some changes I only uploaded the "Global.asax" and "Global.asax.cs". The thing is the .cs files should not even be uploaded ... the project gets compiled and stored in the bin folder as ".dll" and its this file that must be uploaded for the changes to take effect ...

Resources