Piranha CMS routing issue with ASP.NET MVC - asp.net-mvc

I'm in the process of trying to integrate Piranha CMS (v2.2.0) with an existing ASP.NET MVC application. I can run all the original application pages, and the CMS manager pages. I can also see drafts of pages managed by the CMS, but when I try to view the live page version hosted from the CMS I get a HTTP 404 "The resource cannot be found" message.
So the following draft url works:
http://localhost:5316/draft/start
But the following live url fails:
http://localhost:5316/home/start
The original application does have a "Home" controller which I have tried renaming to "Test" in case of conflict issues. I could see the new "Test" located content, but the /home/start url still failed.
As advised, my RouteConfig code is:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Maps.Portal.Controllers" }
).DataTokens["UseNamespaceFallback"] = false;
And my web.config settings are:
<settings>
<managerNamespaces value="" />
<disableManager value="false" />
<passiveMode value="true" />
<prefixlessPermalinks value="false" />
</settings>
I have tried setting the prefixlessPermalinks setting to true but this didn't help.
I'm guessing that Piranha CMS isn't catching the routes for pages hosted with itself? any ideas?

By looking at your config I can see that you have followed the guidelines for setting up Piranha CMS for an existing project by setting passiveMode to true. Let me clarify a bit what this parameter does.
Passive mode is used for applications where you only want to use Piranha CMS as a backend content store and not handle any routing. This means that this parameter effectively turns off all url's to permalinks in the system to not interfere with the existing routes of the application.
If you want to mix your existing application controllers with pages solely generated by Piranha CMS you have to set passiveMode to false which will make the routing for permalinks active again.
Once this is done you will be able to access your pages with or without prefixless permalinks.
Regards
HÃ¥kan

Related

Adding MVC application as a subsite

I have a generic web application up and running http://sites.acme.com.
I want to add a SubSite http://sites.acme.com/subsite1.
In the past to add a new subsite (SubSite1), we would simply publish the project from VS into a sub folder of that folder Sites/SubSite1, and edit the web.config of Sites by adding:
<location path="SubSite1">
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="index.aspx"/>
</files>
</defaultDocument>
</system.webServer>
</location>
Now, trying to publish an mvc website, that doesn't have aspx pages, I'm trying to figure out how to get IIS to recognize that it needs to hit the SubSite1.dll in order to start the home controller, and get the index.cshtml to return.
Do I need to edit any configuration in the sites' web config?
Typically in case of MVC application we don't set default document. We set default controller and default action when we register route. For example following route registration sets default controller as "Home" controller and default action as "Index".
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
So when user types http://mysite/ then it evokes "Index" action in "Home" controller. It is as good as user typing http://mysite/Home/Index
Now, in order to setup your scenario you don't need to add default document configuration as shown in question. Just configure "subsite1" as "application" in IIS under "sites" application and you are good to go provided you have properly setup route for subsite1.

Error - This type of page is not served

I have an MVC (version 5.0) application that I am running from VS 2012 with Web setting of 'Use Visual Studio Development Server'.
When the active file in VS is non .cshtml file, routing works absolutely fine.
However, if the active file is a .cshtml file and I run the application in debug mode, I get this error -
Server Error in '/' Application.
This type of page is not served.
FYI, snippet from RegisterRoutes() -
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Employee", action = "Index", id = UrlParameter.Optional }
);
What makes loading of application behave differently when .cshtml file is active/in focus in Visual Studio?
MVC is built on top of asp.net, so uses the same mechanics for serving files. Because .cshtml files are views and should be served via a controller (MVC) and not served directly, they are blocked as you have found.
You should set the url to the view as defined in the controller (eg /Employee/Index) rather than the page that is used to generate the view (eg /Views/Employee/Index.cshtml)
You can do this by changing the project settings:
right click project
properties
Web
Start URL (or Specific Page)
(it's probably set to 'Current Page')
If, for some reason, you do want to see the source code of the view, then it's blocked via the machine's web.config with this line:
<add path="*.cshtml" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
I recommend you don't change this.

MVC3 Web Application Will Not Publish

I am trying to learn MVC 3, so I am a noob. For now, I just want to make a basic site, that is an HTML page using jQuery and CSS. While I am using MVC, I don't really need a model, since there is not really any data being passed to the application. However, this is creating a problem for me, because I am getting a HTTP 403.14 Forbidden error when I try to publish this site. I think that there is something wrong with the way the application is structured that will not allow it to execute properly when I got to localhost:1081 web site. Here is all I have:
HomeController.cs
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
This just returns the view of Index.cshtml.
Index.cshtml:
#{ViewBag.Title = "My Web Site";} <h2>Web Site Title</h2>
All of my HTML code was put into _Layout.cshtml. jQuery and CSS are used. The site works fine when I do the debug option, but when I try to publish it gives me 403.14 forbidden. I have run the inline command aspnet_regiis -i and it seemed to work, but did not allow the project to run.
Global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
If I move the code in _Layout to Index, it doesn't work. Is there a way I should be linking this to Index.cshtml?
Web.config:
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="_Layout.cshtml" />
</files>
</defaultDocument>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
I do not want directory browsing, and I have tried to play with this option as well. If I enable, it allows me to see the contents but does not render the page.
So two questions: 1.) Do I need to have a model, even though I am not passing any data to the application, just trying to render a site? 2.) Is my site set up / structured properly or what exactly am I doing wrong here?
Thanks,
Nick
No, you don't need a model.
First, don't use the default document. MVC overrides the default document handling and uses the route system.
Second, you don't want to try and use the Layout page as your document. Layout is like a master page, and is used to create a wrapper around your real document.
Third, saying "will not publish" means that you are having problems actually publishing the site via the publish mechanism. Your problem is not that you can't publish, because obviously it is doing so, but that your site isn't executing.
Fourth, 403.14 means it's trying to list the contents of directory, but this shouldn't happen if MVC is configured correctly because MVC's routing takes over. This means you have a problem somewhere in the asp.net pipeline.
Where are you publishing to? Did you configure IIS to setup a site at this location? Given that you are trying to access the site from a different port number, It would seem to me that you have not setup IIS to do this and are instead trying to use the same port that's used for debugging.
In order to publish a site, IIS must be configured to use that location.

ASP.NET MVC2 Routing IIS6 - only default routes work

I've deployed an ASP.NET MVC2 website on a Windows Server 2003 machine running IIS 6.
I'm using pretty much the default routing in a standard MVC project:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Products", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
}
Navigating to http://localhost/MyApplication takes me to the List page just fine. Navigating to http://localhost/MyApplication/Products/Details/21 gives me a 404. This routing worked fine on the inbuilt development server in VS2010.
I've put in the standard IIS wildcard aspnet_isapi.dll mapping mentioned all over the place - navigating to the List page didn't work before I did - but navigating to anything other than the default route is broken.
I'd really like to keep my extensionless URLs. Does anyone have any idea as to why the routing would work for the default webpage, but no others?
*Edit: just tried adding the .aspx extension, ie now my route looks like this:
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Downtime", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
And it has the same behaviour, except this time I get the asp 404 page instead of the html 404 page...
*Edit 2: tried it again using the following route and making sure .mvc was mapped to aspnet_isapi.dll:
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Downtime", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
This time I got an 'Internet Explorer cannot display the webpage' 404-style page. I've now got 3 different 404 errors from using these 3 different methods...
*Edit 3 Return of the Edit: I have the site running in IIS 5.1 on Windows XP professional with only a wildcard remapping on the virtual directory, but heaven forbid I can get it to run on the webserver...
First of all, you should follow this walk-through: http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
(just to make sure you've not missed something). This shows how to get the extension-less and extention'd versions working. You might want to at least check whether the extension'd version works to check that other things aren't misconfigured.
After that, perhaps you should try adding something like this..
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
... as it can really help in determining where your routes are broken.
Some other things to check:
Is IIS configured with ASP.NET? Check properties of the virtual directory. On the VDir select the configuration button and check that the usual ASP.NET extensions are mapped to the .NET 2.0 ISAPI dll. This will be something along the lines of
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.
Is ASP.NET 2 enabled on IIS (under IIS 6 this is off by default): in IIS manager check the Web Service Extensions folder to enable it.
Have you deployed global.asax?
Found it - the routing is actually working, my URLs were not. I was using javascript to build some of the URLs and it turns out that I wasn't linking to
http: //localhost/MyApplication/Controller/Action/ID
I was actually linking to
http: //localhost/Controller/Action/ID
Building the links like this was working on the development server, but once the site was deployed to a virtual directory on the webserver those addresses are incorrect because of the extra application name in the URL.
In conclusion, be careful with your URLs - don't build them out of strings like I did.

host MVC app inside a website

I have a website (not a web application- in visual studio you get two options-create a website/project) running on IIS 6.0. Now I want to develop few features in MVC architecture.
So I created one MVC application in visual studio and everything is working fine on localhost as a separate application. Now I want to host this MVC app also inside the website I have already deployed.
I created a virtual directory(MVCDir) inside the default website in IIS 6.0. The global.asax file which was in root folder I added the routing function-
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.Ignore("{resource}.axd/{*pathInfo}")
routes.Ignore("{resource}.aspx/{*pathInfo}")
routes.MapPageRoute("Default4", "{controller}/{action}/{id}", "~/MVCDir", False, New RouteValueDictionary(New With {.controller = "Home", .action = "Index", .id = Mvc.UrlParameter.Optional}))
End Sub
*** NOTE- If I write routes.ignoreRoute instead of routes,ignore it says- IgnoreRoute is not a member of System.Web.RoutingCollection*
I called this routing function inside application_start function
now when I run domain.com/home/index
How to solve this problem?
it says resource not found
Maybe this is a problem with you child application inheriting configuration from parent. I had a similar problem when trying to put an app under a website.
You'll need to wrap <system.web> in <location> tag with inheritInChildApplications="false"
Example:
<location path="." inheritInChildApplications="false">
<system.web>
<!-- ... -->
</system.web>
</location>
Here you have more detailed explanation.

Resources