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 ...
Related
I am running Sitecore 6.6.0-Update 4, MVC. When I attempt to load the Content Editor, all resources load normally except for the /WebResource.axd and /ScriptResource.axd files. This causes errors when attempting to load the Rich Text Editor, and presumably causes errors elsewhere, as well.
I have verified that routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); is present in Global.asax. Is there anywhere else I can look to troubleshoot this issue?
Here is a copy of one of the error messages, retrieved from Fiddler:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Specified method is not supported.
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.NotSupportedException: Specified method is not supported.
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:
[NotSupportedException: Specified method is not supported.]
System.Web.Routing.StopRoutingHandler.GetHttpHandler(RequestContext requestContext) +36
Sitecore.Mvc.Routing.RouteHandlerWrapper.GetHttpHandler(RequestContext requestContext) +33
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +11507752
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web .HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
What version of MVC did you use? Sitecore 6.6 only supports MVC3, you will get errors with MVC4.
Also - are you using the Sitecore supplied Global.asax or the standard MVC one? The Sitecore version should not have any routing info in there. Here is a copy of my global asax from a 6.6 MVC implementation:
<%#Application Language='C#' Inherits="Sitecore.Web.Application" %>
<script runat="server">
public void Application_Start() {
}
public void Application_End() {
}
public void Application_Error(object sender, EventArgs args) {
}
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
string frameworkVersion = this.GetFrameworkVersion();
if (!string.IsNullOrEmpty(frameworkVersion) && frameworkVersion.StartsWith("v4.", StringComparison.InvariantCultureIgnoreCase))
{
args.User = Sitecore.Context.User;
}
}
string GetFrameworkVersion()
{
try
{
return System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion();
}
catch(Exception ex)
{
Sitecore.Diagnostics.Log.Error("Cannot get framework version", ex, this);
return string.Empty;
}
}
</script>
How did you setup MVC? If in doubt follow John Wests blog on setting it up.
I'm using Sitecore 6.6 with MVC 4 and everything is working fine. I had same problem as yours, but I commented this line
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // commented this line
in Global.asax and this helps.
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
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 :)
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.
I have been trying to set up my Beta 1 MVC app on IIS 6 and cannot get it to run correctly. I have added a Wildcard mapping to the .net isapi DLL as suggested in other blog posts but get the following error when I access the root of the website:
The incoming request does not match any route.
..
[HttpException (0x80004005): The incoming request does not match any route.]
System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) +147
System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext) +36
System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +4
HCD.Intranet.Web.Default.Page_Load(Object sender, EventArgs e) +81
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
I am using the Default.aspx page supplied in the MVC template application that rewrites access to the root of the website properly.
public partial class Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
HttpContext.Current.RewritePath(Request.ApplicationPath);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
}
}
If I try and access a route within the application, such as /Project, I get the standard IIS 404 error page, not the .net error page.
I tried adding the following line to my Web.config httpHandlers section:
<add verb="*" path="*" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
This gave me a different error - the .net 404 error page.
I added the following to my Global.asax, which did nothing:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath.Equals("/"))
Context.RewritePath("Default.aspx");
}
I am using the following route configuration (uses the restful routing supplied by the MvcContrib project):
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
SimplyRestfulRouteHandler.BuildRoutes(routes);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
Any suggestions would be grealy received as I've exhausted all options for the time I have right now.
Many thanks.
Here's what I did to get extensionless URLs working with IIS 6 and ASP.NET MVC Beta 1.
Create a default ASP.NET MVC Beta
project and compile it.
Create a new IIS website pointing to
the application directory.
In the IIS properties for the
website, click the HomeDirectory
tab.
Click the "Configuration..." button.
In the "Mappings" tab, click
"Insert..."
Next to the "Wildcard application
maps" label In the textbox, type in
"c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll"
Uncheck the box labelled "Verify
that file exists" Click OK
Navigate to /home It worked!
You shouldn't need to change web.config at all. You just need to map all requests to IIS to the ASP.NET Isapi dll otherwise ASP.NET will never get those requests.
OK, got it working.
The problem was that I was using msbuild automation to package up the files that I needed to deploy, and I was missing global.asax.
So it looks like if global.asax is not deployed to the site then none of the routes get hooked up. This means that hitting the website root correctly results in the error 'The incoming request does not match any route.', and any other requests no longer get routed through to your controller classes, so result in a 404.
HTH.
Unfortunatly IIS 6 needs a file extension to map the request to the right handler which means you will have to use the .mvc suffix on your controller names, such as /{controller}.mvc/{action}
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
SimplyRestfulRouteHandler.BuildRoutes(routes);
routes.MapRoute(
"Default",
"{controller}.mvc/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
However, the are ways around this depending on your level of control on the IIS 6 server. Please refer to the following pages for more information
http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/
http://www.flux88.com/UsingASPNETMVCOnIIS6WithoutTheMVCExtension.aspx