How to make a catch all route to handle ‘404 page not found’ queries for ASP.NET MVC?

Found the answer myself. Richard Dingwall has an excellent post going through various strategies. I particularly like the FilterAttribute solution. I’m not a fan of throwing exceptions around willy nilly, so i’ll see if i can improve on that 🙂 For the global.asax, just add this code as your last route to register: routes.MapRoute( “404-PageNotFound”, … Read more

How to get a list of all routes in ASP.NET Core?

To get at all the routes, you need to use the ApiExplorer part of MVC. You can either mark all your actions with an attribute or use a convention like this one: public class ApiExplorerVisibilityEnabledConvention : IApplicationModelConvention { public void Apply(ApplicationModel application) { foreach (var controller in application.Controllers) { if (controller.ApiExplorer.IsVisible == null) { controller.ApiExplorer.IsVisible … Read more

Angularjs, passing scope between routes

You need to use a service since a service will persist throughout your app’s life. Lets say you want to save data pertaining to a user This is how you define the service : app.factory(“user”,function(){ return {}; }); In your first controller: app.controller( “RegistrationPage1Controller”,function($scope,user){ $scope.user = user; // and then set values on the object … Read more

Play 2.x: How to make an AJAX request with a common button

For this job you should go with javascriptRoutes as it generates correct JS paths based on your routes.conf. You’ll find usage sample in Zentask sample Anyway, for now you can fix your AJAX call by changing the url to url : ‘@routes.Application.saveDefaultPhoneForUser()’, This way requires it to place the whole JS in template, which is … Read more

Redirect From Action Filter Attribute

Set filterContext.Result With the route name: filterContext.Result = new RedirectToRouteResult(“SystemLogin”, routeValues); You can also do something like: filterContext.Result = new ViewResult { ViewName = SharedViews.SessionLost, ViewData = filterContext.Controller.ViewData }; If you want to use RedirectToAction: You could make a public RedirectToAction method on your controller (preferably on its base controller) that simply calls the protected … Read more

Laravel – Route::resource vs Route::controller

RESTful Resource controller A RESTful resource controller sets up some default routes for you and even names them. Route::resource(‘users’, ‘UsersController’); Gives you these named routes: Verb Path Action Route Name GET /users index users.index GET /users/create create users.create POST /users store users.store GET /users/{user} show users.show GET /users/{user}/edit edit users.edit PUT|PATCH /users/{user} update users.update DELETE … Read more