asp.net-mvc-routing

MVC3 + WordPress IIS Url Rewriting Rules

时光毁灭记忆、已成空白 提交于 2019-12-19 04:09:11
问题 I have a ASP.NET MVC3 website located at http://mydomain.com/mymvcapp/. However, the root of the webiste (mydomain.com) contains a WordPress site running PHP. Therefore, I put the following IIS URL Rewrite rule to allow WordPress to function correctly via its rewriting mechanisms: <rewrite> <rules> <rule name="wordpress" patternSyntax="Wildcard"> <match url="*" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType=

Route testing ASP.NET MVC4

非 Y 不嫁゛ 提交于 2019-12-19 02:47:07
问题 I've been using MvcRouteUnitTester (codeplex and nuget) to run automated unit tests against my routes. A taste of what it can do: // assert incoming route tester.WithIncomingRequest("/Foo").ShouldMatchRoute("Foo", "Index"); tester.WithIncomingRequest("/Foo/Index").ShouldMatchRoute("Foo", "Index"); // assert outgoing route tester.WithRouteInfo("Foo", "Index").ShouldGenerateUrl("/Foo"); It works very well... when it works. It doesn't work well with MVC4 and has not been updated for a long time.

MVC InvalidOperationException with custom error pages

痴心易碎 提交于 2019-12-18 21:27:13
问题 I have custom error pages setup using <customErrors mode="On" defaultRedirect="~/Home/Error"> <error statusCode="404" redirect="~/Home/PageNotFound" /> </customErrors> I created a page that throws and exception and I get redirected to the correct error pages. However I am noticing these errors in elmah on the production webserver: System.InvalidOperationException The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were

VirtualPathProvider in MVC 5

99封情书 提交于 2019-12-18 19:32:43
问题 I can't seem to get a custom VirtualPathProvider working in asp.net MVC 5. The FileExists method returns true but then the GetFile method isn't called. I believe this is because IIS takes over the request and does not let .NET handle it. I have tried setting RAMMFAR and creating a custom handler, as in this solution https://stackoverflow.com/a/12151501/801189 but still no luck. I get a error 404. My Custom Provider: public class DbPathProvider : VirtualPathProvider { public DbPathProvider() :

Multiple types were found that match the controller named 'Home' - In two different Areas

限于喜欢 提交于 2019-12-18 19:00:35
问题 I have two areas in my project. Now when I run the program I get this error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. The request for 'Home' has found the following matching

Correct 404 message for a missing ASP.Net MVC controller

限于喜欢 提交于 2019-12-18 18:27:49
问题 I have an MVC 2 application that should always give a 'nice' 404 page. However currently I get a low level .Net one: "Server Error in '/sitename' Application..." I have a base controller that has a NotFound action that will render the nice 404 page. Missing actions are handled: protected override void HandleUnknownAction(string actionName) { this.NotFound(actionName).ExecuteResult(this.ControllerContext); } So a visit to {site}/ValidController/NotAnAction gets routed correctly. However a

ASP.NET Routing: How to make routeConfig handle a more dynamic URL structure

☆樱花仙子☆ 提交于 2019-12-18 18:03:55
问题 My scenario is as follows: a venue can be part of multiple categories and users can also add filters on multiple category types, so my URLs now are like: /venues/beaches/boats/themeparks (this will display all venues that are beaches AND boats AND themeparks) /venues/beaches/boats /venues etc. So the number of different venue types (beaches, boats, themeparks etc) is both dynamic AND optional. I decided to go with URLRouting so I can start to get the different values in codebehind via Request

Enforce Hyphens in .NET MVC 4.0 URL Structure

孤街浪徒 提交于 2019-12-18 17:22:30
问题 I'm looking specifically for a way to automatically hyphenate CamelCase actions and views. That is, I'm hoping I don't have to actually rename my views or add decorators to every ActionResult in the site. So far, I've been using routes.MapRouteLowercase , as shown here. That works pretty well for the lowercase aspect of URL structure, but not hyphens. So I recently started playing with Canonicalize (install via NuGet), but it also doesn't have anything for hyphens yet. I was trying... routes

Howto automatically add a specific value from current route to all generated links?

岁酱吖の 提交于 2019-12-18 17:13:27
问题 I have site culture in URLs like this: routes.MapRoute( "Default", "{language}/{controller}/{action}/{id}", languageDefaults, languageConstraints) And it works like a charm with a little help from custom MvcHttpHandler that sets current thread's UI culture on every request based on route value. My problem is how do I automatically add the language route value from current request to all outgoing links? E.g. when page /EN/Foo/Bar is requested, I would like this <%=Html.ActionLink( "example

ASP.NET MVC: Routing custom slugs without affecting performance

放肆的年华 提交于 2019-12-18 11:42:43
问题 I would like to create custom slugs for pages in my CMS, so users can create their own SEO-urls (like Wordpress). I used to do this in Ruby on Rails and PHP frameworks by "abusing" the 404 route. This route was called when the requested controller could not be found, enabling me te route the user to my dynamic pages controller to parse the slug (From where I redirected them to the real 404 if no page was found). This way the database was only queried to check the requested slug. However, in