MVC :: How To Add A Custom Route

Feb 15, 2010

I have added a new route to enable me to have nice seo friendly URLs instead of an id field for some news items I am displaying from a database

My global.asax looks like this

[code]...

The problem I have is that since I have added this extra route all my standard URLS (Home etc) are now displaying the controller and action name after them, for example [URL] is being displayed in the URL for my homepage

The news URLS all look fine they are [URL]

why the Controller/Action is now being displayed on non news URL's and how I can stop this happening, would I use a constraint of some sort on the News route ?

View 3 Replies


Similar Messages:

C# - MVC 3 Custom Route Handler - Skip To Next Custom Route Rule?

Mar 14, 2011

Was looking at asp.net mvc complex routing for tree path as an example of how to define a custom route handler for my MVC app. Essentially, I want to give the end user ultimate flexibility in defining the URL for any given page, so I provide them with a field in the interface to specify their own custom URL.

My custom route handler is basically a wild-card handler. It will do a lookup and if it finds a match, map it accordingly. However, if no match is found, I want it to fall back and find the next rule that matches in the global.asax. Is that possible? Or do I essentially need to code the mappings that used to exist in my global.asax into my custom route handler?

View 2 Replies

MVC Custom Routing Long Custom Route Not Clicking In Head?

Jun 5, 2010

I have spent several hours today reading up on doing Custom Routing in ASP.NET MVC. I can understand how to do any type of custom route if it expands from or is similar/smaller than the Default Route. However, I am trying figure out how to do a route similar to:

/Language/{LanguageID}/Question/{QuestionID}/

And what I would like, too, is similar to how SO works. Something like:

/Language/{LanguageID}/Arabic/Question/{QuestionID}/Some-Question-Title

Where "Arabic" and "Some-Question-Title" can be almost anything because what really matters is the ID's

A complete url example might be

[URL]

Am I going beyond what can be done with the extended URL past the language ID?

View 1 Replies

How Will You Do This In MVC Custom Route

Jan 22, 2010

www.yoursite.com/image/http://images.google.com.ph/images/nav_logo7.png

What I need to know here is the Controller Action, and the Global.asax routes

View 4 Replies

Use Custom Route With RedirectToAction (asp.net Mvc)

Mar 8, 2011

I use the RedirectToAction with parameters in my action method

return RedirectToAction("ListThreads", "View", new { category = "1", subcategory = "49"});
After redirect the url comes out like this
http://domain/Forum/View/ListThreads?category=1&subcategory=49
I want it to be generated like
http://domain/Forum/View/ListThreads/1/49

How to do it?

Note : I already have a route in global.asax that is used by all the pages/links.

context.MapRoute(
"Forum_subcategory",
"Forum/{controller}/{action}/{category}/{subcategory}",
new { controller = "View", action = "ListThreads", category = "", subcategory = "" }
);

View 1 Replies

MVC Custom Route Fallback?

Jun 5, 2010

I'm wondering if it is possibile to customize routing in a way that all requests are evaluated by a piece of code, redirected to the relevant controller if a match is found or passed to next rout in list if not found.

sample request:
/my coolpage/another one

the code searches and determine that the right controller for this is Page, action is "list" and id is "123" and so redirects

another request:
/products/list/5

code finds no match al passes it back to next route that knows how to handle it...

View 1 Replies

Custom Route With More Than One Parameter In Url (customer - Extra Info)

Jan 31, 2011

I have a multi tenant system and I need to allow administrators to edit the information of other customers. I believe the correct way to do this is to append the customer ID to each request, and update my routes accordingly. How do I make ASP.NET accept and use something like this in the controller (order doesn't mean much to me): [URL] and how would I pass and consume that in my controller? The ASP.NET tutorials skip this... (or I don't know where to search)

View 1 Replies

MVC :: Custom Route Returns 404 When All Optional Parameters Are Null?

Feb 19, 2010

I get a 404 error when I navigate to the following URL using the route below:

http://localhost:53999/properties/

However, all the following are correctly routed to the List action in my controller:

http://localhost:53999/properties/usa/new-york/manhattan/12

http://localhost:53999/properties/usa/new-york/manhattan

http://localhost:53999/properties/usa/new-york

http://localhost:53999/properties/usa [Code]....

In PropertiesController.cs: [Code]....

It looks like it should just go to the default controller/action,

View 5 Replies

C# - Custom MVC Route: Changing Where The Views For A Controller Are Located

Jan 5, 2011

So I have a controller called EmployeeController, and all the Views are in /Employee.

I'd like to create a route so that the EmployeeController will use /Employees and /Employees/Add instead of /Employee and /Employee/Add.

I keep finding articles about how to change the route to go to different actions.

View 3 Replies

MVC :: Webforms Route / Implementing Route In Global.asax

Mar 13, 2011

I tried to mix asp.net 4 webfrom and ASp.Net MVC 3. I add required lines in webconfig, but I've issues implementing route in global.asax

Currently I use several routes for webfroms. routs template are like below

routes.MapPageRoute("Node", _
"article/sport/{nID}/", _
"~/article/articleview.aspx")

I encounter error, when I add below lines to global.asax

routes.MapRoute( _
"Defaultss", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)

I want to know how could I mix ASp.Net MVC routes with webforms routes.

View 3 Replies

MVC :: A Route Named 'Admin_default' Is Already In The Route Collection?

Mar 9, 2010

when i run the app i got this error

A route named 'Admin_default' is already in the route collection. Route names must be unique.
Parameter name: name

this is my AdminAreaRegistration

[Code]....

View 2 Replies

Route Constraints And Empty Route?

Sep 24, 2010

I have a url that I want to map routing to:

[URL]

where tabvalue is one of: "personal", "professional", "values" or nothing.

I want to map it to a route like:

Member/Edit/{tab}

But my problem is - I don't know how to specify such constraints. I'm trying this regex:

^[personal|professional|values]{0,1}$

but it only works when I use url

[URL]

[URL]

and doesn't work for

[URL]

how to specify the correct constraint?

P.S. I'm not using MVC, just asp.net WebForms

View 6 Replies

MVC :: How To Add A Certain Route

Apr 5, 2010

I want to do the following:

routes.MapRoute("testwithoutcontroller", "Overview/Index/{year}", new {year = 2010});

But it fails when I call Overview/Index/2010 and gives me this error:

The RouteData must contain an item named 'controller' with a non-empty string value.

What must I do in order to only have Overview/Index be possible for my route?

View 3 Replies

MVC :: Why Do Route Values Not Get The New Value

Jul 11, 2010

When I do an Html.RenderAction( action, controller, new { varName = value } ); if the original request had a parameter equal to varName, then the value is not changed in a render action.

Example:

1. Post to "C1/A1" with a string var _test = "abc"

2. Inside C1/A1 get some data and return a partial view

3. Inside the partial view I invoke an action on another controller. The action has an input variable with the same name and type (string _test) Html.RenderAction( "A2","C2", new {_test="fgh"});

4. the value in _test that arrives at C2/A2 is still "abc"

I've traced through it step by step, and the value used in the view render action call is correct, but in the next trace step, the value received at C2/A2 is incorrect.

If this is not an error, and creating a new route value to pass in render action is not the correct way to handle this, what is?

View 7 Replies

How To Access The Route

Mar 11, 2011

I'm using ASP.Net 4 URL routing on a web forms site.

I have multiple routes to a single page

routes.MapPageRoute("","our-services", "~/Information.aspx");
routes.MapPageRoute("","our-company", "~/Information.aspx");

On the destination page (Information.aspx) how can I tell which route was used to get there, for example was it from our-services or our-company?

View 2 Replies

Where To Use Route-name Of Routing In Mvc

May 19, 2010

i'm new to routing in aspnet mvc.. i have following code:

[code]....

when i enter "localhost/school" in addressbar, it is giving 404 error instead it should route to my "schoolIndex" action

i have given route-name as "School" where it is used ?

View 1 Replies

How To Route Url With # Character

May 3, 2010

How to route url contains # sharp character like this:

~/page.aspx#/Home

to be:

~/Home

View 2 Replies

How To Route URL From One Domain To Another

May 24, 2010

I am an C# ASP.NET developer. I am trying to route URL from one domain to another using Godaddy IIS Virtual dedicated server or Dedicated server for ASP.NET.

For example I have a website application for client_A in my server which is intended to be use by multiple clients with different products.

An example URL: www.myserver.com/client_A/product/bear/?productid=1 or using pretty URL www.myserver.com/A_Application/product/bear/1

I would like to setup for my client to point to client_A using his/her domain.

My Client example URL will be: www.hisserver.com/product/bear/?productid=1 or using pretty URL www.hisserver.com/product/bear/1

View 1 Replies

How To Route Subdomain

Feb 27, 2011

I have made an asp.net mvc 3 application with an area called blog. I want to route this area to my subdomain blog.mywebsite.com. How can I achieve this?

How do I need to define my route? Do I have to configure the DNS?

Currently I just use the default area route. I can access my blog area for now at this way.
mywebsite.com/blog

View 1 Replies

Id In The Beginning Of The Route In MVC?

Feb 21, 2011

I have a situation where I want a route in my application so that the application's index method can recognize this[URL]The problem is that, when I set up the route corresponding to the first URL, the route for the second URL does not work (even if I set up a separate route for that).

View 2 Replies

How To Get Route Name From RouteData

Oct 17, 2010

I have several routes defined in my Global.asax; now, when I'm on a page I need to figure out what is the route name of the current route, because route name drives my site menu. I can't find a way to get current route name.

View 4 Replies

MVC :: Route To An Outside URL From Within A Controller?

Dec 17, 2010

I'm embarrassed to ask this question, but not sure what the syntax is to call a URL from within a controller (not associated with the application).

The reason I need to do this is because I am sharing authentication with another webforms app and would like to clear out the session variables before rerouting to that other URL. I'm just not sure of the syntax to route from an Action method to a URL like www.microsoft.com?

View 2 Replies

C# - Add An Additional Route?

Mar 31, 2010

Here is my default route.

context.MapRoute(
"CreditReview",
"Site/{sitecode}/CreditReview/{controller}/{action}/{id}",
new { action = "Index", id = "" }
);

I'm looking to add 'status'. This is what I currently have and it isn't working. I haven't worked with routes.

context.MapRoute(
"CC",
"Site/{sitecode}/CreditReview/{controller}/{status}/{action}/{id}",
new { action = "Index", id = "" });

View 2 Replies

Custom Server Controls :: Custom Tag Not Found For Control / Error: Unknown Server Tag 'custom:AjaxValidator'

Jan 3, 2011

Hope this is the correct forum for this question. I am using VWD 2010 an have a web project and get the following error upon execution:

Parser Error Message: Unknown server tag 'custom:AjaxValidator'.

My code is as follows in the .cs file:

[Code]....
[Code]....

View 1 Replies

Way To Register Default Route

May 7, 2010

I am using asp.net C#/3.5 and stuck.

PHP Code:
Route myroute1 = new Route("{controller}/{action}/{slug}", new MyRouteHandler());
Route myroute2 = new Route("{controller}/{action}", new MyRouteHandler());
Route myroute3 = new Route("{controller}", new MyRouteHandler());
Routes.Add(myroute1);
Routes.Add(myroute2);
Routes.Add(myroute3);
[code]...

View 12 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved