Code Monkey home page Code Monkey logo

routemagic's Introduction

RouteMagic

A library of useful extensions to ASP.NET Routing.

Installation

Use NuGet to install RouteMagic or RouteMagic.Mvc.

Install-Package RouteMagic.Mvc

For more information, read the introduction blog post.

RouteMagic supports all these features!

routemagic's People

Contributors

antonmoiseev avatar haacked avatar psantiago avatar seththetech avatar wireduk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

routemagic's Issues

MapDelegate overrides default routing when calling with Html.ActionLink

Given the following routes

routes.MapDelegate("RouteFailureTest", "home/test",
context => new HomeController().HomeTest(context.HttpContext));

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }//, // Parameter defaults
);

a call to @Html.ActionLink("Log Off", "Logout", "User") always matches the "RouteFailureTest".

My guess is that it's related to the lack of default controller/action values so the ActionLink, providing the default values matches the delegate route.

It's fairly simple to reproduce, use a standard MVC3 application (with default Home/Account controllers) add the MapDelegate route above and check the Login/Home/About Us links. They will always match the RouteFailureTest route.

routes.MapRoute(
"ShouldntMatch", // Route name
"home/test", // URL with parameters
null // Parameter defaults
);

Confirmed it's the null defaults. This route produces the same results as the MapDelegate by matching any Html.ActionLink or other similar helpers

Json Results have RouteDebugging Appended

When testing routing using the Route Debugger, any Json results from an action (even if marked as a JsonResult) has the Route Debugging information appended which leads to parse errors consuming the resulting Json. Must disable route debugging when testing any JsonResult call.

Redirect routes are registered without name, so @Url.RouteUrl("name"...) fail

Redirect() call ignores the name with which "old" rout is being registered in passed Func. Instead it takes just the result Route and calls routes.Add((RouteBase) redirectRoute); (without name argument).

This leads to situation that if some page contains @Url.RouteUrl("name"...) link, it fails to render due to absense of named route.

PS: I need many routes to be redirected to home page, so I have code like
var homePage = routes.MapRoute(...);
routes.Redirect(...).To(homePage);
routes.Redirect(...).To(homePage);
...

I would like to avoid registering each of the deleted routes separately since it looks redundant...

Route Debugger Not Showing Any Route Information

When I downloaded the RouteMagic solution and checked the RouteDebugger project I found that the following check was causing my issue:

if (!IsRoutedRequest(request) || !request.ContentType.Equals("text/html", StringComparison.OrdinalIgnoreCase))
{
    return;
}

Commenting out this check allows me to see the route information but now it adds it to everything. js files etc. As @cluggas suggested on the blog post (http://haacked.com/archive/2011/04/13/routedebugger-2.aspx) when I changed this check to look at the response content type things seem to be working fine.

Unrelated Question: How do I format C# code in github :P

General questions - not an issue but seeking more info

Does the EditableRoutes process presume to replace the Routes table. or does it augment? Do you run it before or after the main Routes are defined elsewhere?

I technically have the pkg 'working', in that it is executing (from Global.asax.cs) and updating the Routes based on ./Config/Routes.cs, but it's wiping out the Routes that have collected up to this point.

It seems that the Collection data is not being passed into the Routes.RegisterRoutes() method when the file is processed. What might I be missing, do you think?

RouteDebug doesn't work as a NuGet package

@haacked, I love your work and your MVC RouteDebugger utility is used a lot, also by me.

However - somewhat strangely - it doesn't quite work as a NuGet package for me. I have only gotten it to work by manually downloading the zipped .dll, adding that to the /bin and then adding a reference in my project in Visual Studio. But then of course when I delete my bin and obj from my project - for instance to fix some obnoxious error in Visual studio when cleaning is not enough - I have to redo this progress.

So I WOULD like to have it as a NuGet packages so it can 'survive a clean'.

For the RouteDebug package I get a simple 'does not exist' compile error:

The type or namespace name 'RouteDebugger' does not exist in the namespace 'RouteDebug' (are you missing an assembly reference?)

This happens on the line

RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
that I added in the Application_Start() method of Global.asax.cs

I have tried removing and re-adding the package as well, but that doesn't help. I am currently using Visual Studio 2013 (Professional): MVC5 (but had this issue in VS 2010 as well).

Note: I logged this as a general issue before, but am now logging this issue on the RouteMagic repo, so I installed this NuGet package (removed the RouteDebugger package first). This gives me a similar error on the same line:

The name 'RouteDebug' does not exist in the current context

RouteMagic redirection giving 404 instead of redirecting

Hello,

I have rewritten an old WebForms site in MVC5 (Visual Studio 2013 Ultimate Update 4, Windows 7 64-bit), and want to add permanent redirection from the old URLs to the new. Reading your blog post about RouteMagic (http://haacked.com/archive/2011/02/02/redirecting-routes-to-maintain-persistent-urls.aspx/), I thought this would do the trick.

I added the NuGet package, and then added the following to the end of the RegisterRoutes() method in the RouteConfig class...

routes.Redirect(r => r.MapRoute("old", "Default.aspx")).To(routes.MapRoute("new", "Home"));

However, if I try to access http://localhost:8109/Default.aspx, I just get a 404 in the browser. It doesn't redirect at all.

What am I doing wrong? I reproduced the problem on a brand new, out-of-the box MVC project. I just added your package and the one line of code shown above.

Thanks for any help you can give.

Redirect Route Not working

I have a route configured as follows:

var defaultHomeRoute = routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}", 
                MVC.Home.Index(), 
                defaults: new { id = UrlParameter.Optional });
routes.Redirect(
                r => r.MapRoute(
                "ImageReviewDisabled",
                "Review/{action}"),
                permanent: false).To(defaultHomeRoute);

However, when I browse to the url /Review/Index, it does not redirect me to /Home/Index, as I would expect. I'm not sure if there's anything else I need to do in order to get this to work. My intent is to prevent users from accessing the ReviewController for a while since we're re-developing, and the app is still in a testing cycle.

Am I missing any other configuration to get this temporary redirect to work?

Namespace Distinction

Hi I'm using MVC 4 and I wanted to use this library, it looks very useful for redirect.

However for my solution I have some controllers that have the same name but in a different namespace. Some of them in the root some of them in areas. After adding this library alot of my routes didn't work anymore due to it being unable to decide which of the two controllers it should use. When it should be able to decide based on the area.

RouteMagic on Mono

I'm using the default project for Nuget.Server package, that uses routemagic.

When I click at "nuget/Packages" link, i got a 404.

Using nginx with mono framework 4.

Unit testing fails with GroupRoute

We have unit tests that test our routes and are unable to add a group route feature as it breaks when loading the routes with the following error:

The application relative virtual path '~/' cannot be made absolute, because the path to the application is not known.

somepathvalue here is replacing the actual path value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.