asp.net-mvc-routing

Prevent static file handler from intercepting filename-like URL

只愿长相守 提交于 2019-12-01 03:26:13
In my web application I have a route which looks like this: routeCollection.MapRoute( "AdfsMetadata", // name "FederationMetadata/2007-06/FederationMetadata.xml", // url new { controller = "AdfsController", action = "MetaData" }); // defaults The idea behind this route was to work better with Microsoft AD FS server (2.0+) which looks for AD FS metadata at this point when you just specify a host name. With MVC3 all worked fine. But we upgraded the project to MVC4 recently and now the call for this URL results in a 404, the handler mentioned on the error page is StaticFile and the physical path

MVC 5 Routing Attribute

岁酱吖の 提交于 2019-12-01 03:16:11
I have the Home Controller and my Action name is Index. In My route config the routes like below. routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); Now I call my page like http://localhost:11045/Home/Index is correct. If I call my page like following it should redirect to error page. localhost:11045/Home/Index/98 or localhost:11045/Home/Index/?id=98 . How to handle this using routing attribute. My Action in Controller look like below. public

What is wrong with my area routing in my bin deployed MVC4 app?

ε祈祈猫儿з 提交于 2019-12-01 03:10:20
问题 I have just deployed an MVC4 .NET 4.0 app to my web host, for 'live' deployed testing. Non -area routes are working fine, e.g. my @Html.ActionLink("Register as a Client", "Register", "Account", new { registrationType = "Client"}, null) link works fine, and the link opens the correct page. However, with a link to an area based action like this: @Html.ActionLink("Authors", "Index", "Home", new { Area = "Author", registrationType = "Author" }, null) the link actually rendered to the browser is

MVC: How to manage slahses in URL int the first route parameter

三世轮回 提交于 2019-12-01 02:49:44
问题 I need to map two variables that could contain slashes, to a controller, in my ASP MVC application. Let's see this with an example. Repository and Path will be URL-encoded parameters. Repository can have 0 slashes or 1 slash as a maximum (rep or rep/module) Path can have an arbitrary number of slashes. For example these are valid URLs: http://mysite/rep/Items http://mysite/rep/module/Items/foo/bar/file.c Someone could give some suggestions about how to define this route? 回答1: Looks like a

Creating multilingual not found page in MVC

与世无争的帅哥 提交于 2019-12-01 02:48:10
问题 We have a multilingual website that has content in four languages.Every language is understood by the language name that we add at the first of our url. This is our routeConfig.cs: routes.MapRoute( name: "Default", url: "{lang}/{controller}/{action}/{id}/{title}", defaults: new { lang = "fa", controller = "Home", action = "Index", id = UrlParameter.Optional,title = UrlParameter.Optional } and this is generated the url: /en/ContactUs/Index Also, in our controllers we get the language name from

Passing querystrings to RedirectToRouteResult (beside controller and action)

江枫思渺然 提交于 2019-12-01 02:36:25
I have the following code: var routeDictionary = new RouteValueDictionary {{"action", "Login"}, {"controller", "Persons"}}; filterContext.Result = new RedirectToRouteResult(routeDictionary); That will produce " /Persons/Login " How can I pass an aditional querystring to the previous code? so that it produces " /Persons/Login/?someQuerystring=someValue " Try this: filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "action", "login" }, { "controller", "persons" }, { "someQuerystring", "someValue" } } ); 来源: https://stackoverflow.com/questions/17150647/passing

Having trouble with a simple MVC route

扶醉桌前 提交于 2019-12-01 01:27:10
Having some trouble with some routes. I don't fully understand the MVC routing system so bear with me. I've got two controllers, Products and Home (with more to come!). I want to have the views within the Home controller accessible without having to type Home in the url. Essentially I want to turn www.example.com/home/about into www.example.com/about, however I still want to preserve the www.example.com/products. Here's what I have so far. routes.MapRoute( "Home", "{action}", new { controller = "Home" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "home",

Why is ASP.NET MVC ignoring my trailing slash?

社会主义新天地 提交于 2019-12-01 00:57:46
问题 Consider the following route: routes.MapRoute( "Service", // Route name "service/", // URL with parameters new {controller = "CustomerService", action = "Index"} // Parameter defaults ); Using Url.Action("Service", "CustomerService") produces an url of /service instead of the expected /service/ Is there any way to get this to work, or do I have to resort to implementing my own routing deriving from RouteBase ? 回答1: Legenden - there is no immediate solution to the problem. You may have run

Html.ActionLink construct wrong link when a non-mvc route is added

我怕爱的太早我们不能终老 提交于 2019-12-01 00:35:19
问题 I have an application here with a mix of webform and mvc. I specify the routing as below routes.Add("AspxRoute", new Route("Upload/New", new WebFormRouteHandler<Page>("~/Uploads.aspx"))); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); So that virtual path to "Upload/New" actually maps to an aspx webform page. But my problem is that Html.ActionLink("Test", "Controller

MVC3 + WordPress IIS Url Rewriting Rules

这一生的挚爱 提交于 2019-12-01 00:14:23
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="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php"/> </rule> </rules> <