asp.net-mvc-routing

Hide one controller name from mvc url, show other controller names

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 06:06:04
I have two controllers, HomeController and ResourcesController. I want to hide the Home/ from the url when action on HomeController is requested, but for ResourcesController (or any other controlelr) I want to keep the controller name in url. E.g. /Home/Products will be /Produtcs, but /Resources/Banana should stay /Resources/Banana These are my routes: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "SpecificRoute", url: "{action}/{id}", defaults: new { controller = "Home", action = "Home", id = UrlParameter.Optional }); routes.MapRoute( name: "Default", url: "

Match route relative to path

大兔子大兔子 提交于 2019-12-06 05:26:22
I want any URL that ends with /templates/{filename} to map to a specific controller using either a route attribute i.e. something like: public class TemplateController : Controller { [Route("templates/{templateFilename}")] public ActionResult Index(string templateFilename) { .... } } which works, but the links referencing this route are relative so http://localhost/templates/t1 -- works http://localhost/foo/bar/templates/t2 -- breaks (404) I need something like: [Route("*/templates/{templateFilename}")] You cannot accomplish something like this with attribute routing. It is only possible to do

Returning a view with it's model from an ActionFilterAttribute

不羁岁月 提交于 2019-12-06 04:42:50
问题 When implementing error-handling using the built-in validation-helpers on a strongly-typed view, you usually create a try/catch block within the controller and return a view with it's corresponding model as a parameter to the View() method: The controller public class MessageController : Controller { [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Models.Entities.Message message) { try { // Insert model into database var dc = new DataContext(); dc.Messages.InsertOnSubmit(message); dc

Is it OK to send a 301 redirect with an action filter?

安稳与你 提交于 2019-12-06 04:39:32
I'm writing a new asp.net mvc application and I've been toying with the idea of allowing my user to post short, concise urls to content that he has posted. Those short url's will be handy in cramped spaces like Twitter and comment areas. I like this idea as I'm not a huge fan of url shorteners because they're so vague and you're never really sure what you're going to get. Instead of using a url shortener I want to give my client the ability to post: http://domain.com/p/234 which does a 301 redirect to: http://domain.com/2009/08/10/this-is-the-content-title Now, this is a pretty simple process

ASP.NET MVC4 with webforms Default.aspx as the start page

☆樱花仙子☆ 提交于 2019-12-06 04:39:08
问题 I had an ASP.NET MVC4 app with the following routing defined in the Global.asax.cs. The app's start page is Index.cshtml view that is returned from the action method Index() of the Home controller. I then added a legacy ASP.NET WebForms app that had Default.aspx as the start page. How can I make this Default.aspx page as the start page of this integrated MVC+WebForms app: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes

How does routing for ASP.NET Web Pages work without global.asax

安稳与你 提交于 2019-12-06 04:33:21
Web server with ASP.Net 4.0 installed, Web Pages 2.0 DLLs bin deployed. Pages written in cshtml/razor, but routing is not working. What is required on the server to activate routing when using only Web Pages as opposed to full MVC (where I'd have my routes defined in global.asax)? Right now I can only call my pages using the traditional URL and query string. Any pointers appreciated. There are two kinds of "routing" available in the Web Pages framework. The default routing works on matching URLs to file paths. It is quite flexible in that it allows for additional URL segments that populate a

URL Redirection in ASP.NET MVC

你说的曾经没有我的故事 提交于 2019-12-06 04:31:10
问题 I was working on a Website which was earlier built with ASP.NET Web Forms and now is built with ASP.NET MVC. We made the new MVC version live last week. But the old login url which is www.website.com/login.aspx has been bookmarked by many users and they still use that and hence they get 404 errors. So I was wondering which would be the easiest and best way to redirect the user from the old url to the new mvc url which is www.website.com/account/login Like this login url, I am expecting the

Does ASP.NET MVC create default routes for areas

牧云@^-^@ 提交于 2019-12-06 04:10:26
问题 I have a couple of areas in my MVC 3 application Auth and Users. I am using Phil Haacks Route Debugging tool to view a list of my routes and see which one gets selected based on my url. However there are a couple of routes present that I have not created in either my AreaRegistration file or Globalasax and I don’t know where they have come from or how to get rid of them. The routes are highlighted in yellow below. You can also see that I have created a default route in my Auth area

ASP.NET MVC. How to suppress showing default culture in URL?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 02:59:38
here is question. I have an localized asp.net mvc website. Localization done by next steps: 1. for each route I automatically add an {culture} url segment with default value to "ru". I want my urls to be with culture only for foreign cultures. For example: http://mysite.com/ua/contacts - ukrainian http://mysite.com/fr/contacts - francis http://mysite.com/contacts - russian I can't arrive this, because @Url.Action method always returns url with culture, even then it is a default culture. Help me please! routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with

With asp.net MVC4, how can I make my root index.html be executed by default?

我与影子孤独终老i 提交于 2019-12-06 01:48:31
问题 For much of my web site, I want normal routing to occur the MVC way. However, when the app first launches, I don't want the route to go to /Home/Index.cshtml. I want it to go to simply /Index.html My current RegisterRoutes looks like this (and does not achieve my goal) public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("index.html"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new