Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search


MVC Routes: Defining Route Including Subpaths

Let's say I want to forward all requests at /js/* to a JavaScript controller Index method. In other words, these routes should all invoke JavaScriptController.Index():


What would the route definition be in my Global.asax.cs file? This doesn't seem to work:

routes.MapRoute("JavaScript", "js/{*path}",
new { controller = "JavaScriptController", action = "Index" });

The breakpoint is never invoked during Debug mode with:

public class JavaScriptController : Controller
public void Index(string path)
var browser = HttpContext.Request.Browser;

View 2 Replies (Posted: Jan 4 at 22:19)

Sponsored Links:

Related Forum Messages For ASP.NET category:
MVC :: Adding A Few Routes To A Route Value Dictionary?
On a controller I am adding a few routes to a route value dictionary:


But I get two errors:

'object' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

Posted: Oct 27, 2009 02:50 PM

View 1 Replies!   View Related
How To Generate A Path / Url From A Route In The Routes Table
I have an ASP.NET MVC web application, and I've registered a number of routes in my Global.asax.

I would like to know how I can programmatically build (generate a string url) any one of those registered routes from within my Controller.

I did the same thing in Web Forms with .NET 4.0 using Page.GetRouteUrl(routeName, routeParams) but can't figure out how to do the same thing in MVC (I'm an MVC newbie).

Posted: Nov 25 10 at 14:40

View 1 Replies!   View Related
MVC Routes Adding An Optional Parameter At The Beginning Of A Route
I have the following routes setup in my route config file. I have a config reader that maps these to MVC-style routes.

[route name="customers" url="customers/{statename}/{marketname}/{pagenumber}"]
[controller name="Customers" action="Display" //route]
[route name="pcustomers" url="{customername}/customers/{statename}/{marketname}/{pagenumber}"]

Posted: Aug 7 10 at 19:54

View 2 Replies!   View Related
Security :: Forms Authentication With Route Handling - Error Routes Not Recognized, Returns To Login
I just created a small site with form authentication with route handling. Without forms authentication, the pages route just fine. With forms, it returns back to the login page as it is not one of my allowed locations specified in my web.config file.

I know I probably need to write a custom route handler. Does anyone have an example I can follow for this?

Posted: Oct 01, 2010 02:48 AM

View 1 Replies!   View Related
MVC :: Routes.IgnoreRoute Not Ignoring Routes?
I'm trying to prevent direct file requests from being accepted, and have tried this:


None of these worked. I want the rule to exclude any file of any filename in any directory with a matching extension. How can this be done?

Posted: May 25, 2010 07:36 PM

View 11 Replies!   View Related
MVC :: Default Route And RouteUrl / Specify Controller And Action Instead Of Having The Route On Global.asax?
I am sending a route to a server as follows:


Can't I specify controller and action instead of having the route on Global.asax? How?

Posted: Dec 30, 2009 04:07 PM

View 3 Replies!   View Related
How To Mix DynamicData Routes With Mvc Routes
I am trying to create an Area for running DynamicData with scaffolding as an administration part. It's probably working as it should but I can't get the routing to work.

In my global.asax I have the following function to register the routes:


Unfortunately the "best" thing that happened to me so far was that when I check the default tables I get a message about (MetaModel.VisibleTables)


The problem is that I don't know why this is. Is it the routing or something else? Is it perhaps some security thing or can I not put dynamic data inside an area?

The DynamicData folder itself is located in the root of the application since that is the convention it uses and I have no intention to override that.

Posted: Jan 9 at 22:16

View 1 Replies!   View Related
MVC :: Webforms Route / Implementing Route In Global.asax
I tried to mix 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}/", _

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.

Posted: Mar 13, 2011 09:24 PM

View 3 Replies!   View Related
MVC :: A Route Named 'Admin_default' Is Already In The Route Collection?
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


Posted: Mar 09, 2010 06:52 PM

View 2 Replies!   View Related
Route Constraints And Empty Route?
I have a url that I want to map routing to:


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

I want to map it to a route like:


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


but it only works when I use url



and doesn't work for


how to specify the correct constraint?

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

Posted: Sep 24 10 at 15:52

View 6 Replies!   View Related
C# - MVC 3 Custom Route Handler - Skip To Next Custom Route Rule?
Was looking at 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?

Posted: Mar 14 at 20:09

View 2 Replies!   View Related
Web Forms :: Defining Web Parts For All Users?
Can an administrator can define a web page with web parts for all users ? That is, can an administrator add a web parts for all users, set properties for the web partsand then publish the web page ? All users then see the same page with the same web parts and can't remove the web parts or set different properties. All they could do is to minimize the web parts, move them around but can't close them. When administrator updates the web page with more web parts, I want those changes to override the an indivisual user's personlization. Is that possible ?

Posted: Nov 23, 2009 08:49 PM

View 5 Replies!   View Related
.net - Trouble Defining Bindings Using Ninject?
having trouble defining bindings using ninject.I am in a standard ASP.NET WebForms application. I have defined an http handler to Inject dependencies in pages and controls (Property injection).Here is what I am trying to do:I am creating a custom combobox usercontrol. Based on the value of an enum on that combobox, I want to be able to Inject a different object in a property (What I am trying to do is a bit more involved than that, but answer to this should be enough to get me going).

Posted: Mar 28 at 13:44

View 1 Replies!   View Related
AJAX :: Got An Error On A Page Defining A Web Service
I recently upgraded from VS2005 to VS2008. I did a full install of VS2008, then opened my existing project in it. This launched the conversion wizard which successfully converted my VS2005 project to VS2008 and it opened in VS2008 owever, when I first tried to build the solution in VS2008, I got an error on a page defining a web service saying

Posted: Feb 26, 2010 08:01 PM

View 6 Replies!   View Related
MVC :: A Partial Method May Not Have Multiple Defining Declarations?
i m getting the following error while i m running my application of NerdDinner Web application that i m practicing for MVC framework ,

error : A partial method may not have multiple defining declarations

Posted: Aug 17, 2009 06:46 AM

View 2 Replies!   View Related
SQL Query Error In Defining Alias For Column
My following sql query giving me the following error, What does it mean. Am i defining the alias fir column in wring way. Please help me out with this. My error is this and i am putting query just below the error. Error in SELECT clause: expression near 'Year'. Missing FROM clause. Unable to parse query text.

SELECT [tbl_students].passing_year as Passing Year,[tbl_branch].branch_name as Branch_Name FROM [tbl_students], [tbl_course], [tbl_branch] WHERE [tbl_students].course_id=@courseId
AND [tbl_students].branch_id IN(64)
AND [tbl_students].course_id=[tbl_course].course_id AND [tbl_students].branch_id=[tbl_branch].branch_id
AND (@firstYrPercent is null OR [tbl_students].first_year_percent>=@firstYrPercent)
AND (@secondYrpercent is null OR [tbl_students].second_year_percent>=@secondYrPercent)
AND (@thirdYrPercent is null OR[tbl_students].third_year_percent>=@thirdYrPercent)
AND (@finalYearpercent is null OR [tbl_students].final_year_percent>=@finalYearpercent)
AND (@currentDegeePercentage is null OR [tbl_students].current_degree_percent>=@currentDegeePercentage)
AND (@passoutYear is null OR [tbl_students].passing_year>=@passoutYear)
AND (@currentBacklog is null OR [tbl_students].current_backlog=@currentBacklog)
AND (@sex is null OR [tbl_students].gender=@sex)
AND (@eGap is null OR [tbl_students].gapin_education<=@eGap)
AND (@highSchoolPercentge is null OR [tbl_students].highschool_percentage>=@highSchoolPercentge)
AND (@higherSchoolPercentage is null OR [tbl_students].ssc_percentage>=@higherSchoolPercentage)
AND (@grauationPercentage is null OR [tbl_students].graduation_percentage>=@grauationPercentage)
AND (@diplomaPercentage is null OR [tbl_students].diploma_percentage>=@diplomaPercentage)
AND (@noOfAtkt is null OR [tbl_students].number_of_ATKT<=@noOfAtkt)
AND (@validDate is null OR [tbl_students].DOB>=@validDate)

Posted: Sep 4 10 at 13:00

View 1 Replies!   View Related
LINQ To SQL Defining Where Class Depending On Parameters?

I am going to return an Object depending on the Class and Year params. I want to remove the where condition when the Class and Year parames are null or zero.

Posted: Jan 26 10 at 17:24

View 2 Replies!   View Related
MVC :: Defining Validation Rules With Data Annotations?
Defined RegisterModel class - with some validation rules for creating new users, and this works fine.

Then I get this class, strip few properties and wanted to reuse it as UserInfo_Form_Model, for editing user properites.

No changes, just deleted few items, renamed and reused in strongly typed View for editing.

And result of validation is: -

[DisplayName("Name")] works fine, showing correct

[StringLength(20, ErrorMessage = "xxxx...")] - not working, no message showed whensupposeto be one

[Required(ErrorMessage = "xxxx.")] - not working, not showing messages when delete required values?

but (ModelState.IsValid) is false when I checked it in controller (it had to be because required value is missing)?

Is it this onlypartiallycorrect and how this can be?

Well this is a bit frustrating because it cant be simpler than this and I cant make this simple code reuse.

Posted: Sep 24, 2010 11:05 AM

View 3 Replies!   View Related
Web Forms :: Default Submit Button Without Defining It In A Tag?
I developed a portal with master pages, where there is a Form tag inside the master page.

Then in the container page, I have several search pages where users expect to press Enter key after writing the search criteria inside a textbox and perform search.

Since I can't use a form tag within that container page as it would lead to nested FORM tags and will create an error.

Is there a workaround about that?

Posted: Sep 16, 2009 10:50 AM

View 2 Replies!   View Related
Databases :: Defining Index On Table Columns?
On one of our tables, a default clustered index is defined on the primary key by sql server 2005. The table also contains forign key columns and has got over 2 million rows. There are very frequent INSERT, UPDATEand DELETE functions on this table. Recently some of the SELECT queries which primary operate on the forign keys have become very slow (resulting in application timeout). To fix the problem, I defined an index on one of the primary keys which gave me very quick results.I don'tknow much about indexes.

1.Since I defined a new index (on the forign key)in addition to the existingdefault index, what kind of index (clustered or non-clustered) have I defined?

2. What performance impact does it have on the rest of the system? Is it going to break something else?

3. I read about fill factor. What is this and how does it effect the system?

4. Is the new index physically going to make any changes?

5. In case I delete this index later on, will the database return to the existing state or it will be a different state from now?

Posted: Mar 05, 2011 03:14 PM

View 1 Replies!   View Related
Web Forms :: Make Menu Manually By Defining Items?
i am just trying to make a menu "manually" by defining menu items, i am also using css adapter for easy styling. I am facing a problem on postback, i am not getting the selected item (there is no item with class AspNet-Menu-Selected), even without css adapter i think. My menu is simple, there is master page, a couple of pages, the menu is on master page. why, and how can i solve this.

Posted: Jan 07, 2010 10:59 AM

View 4 Replies!   View Related
C# - Defining Status Of Data Via Enum Or A Relation Table?
I have an application which has rows of data in a relation database the table needs a status which will always be either Not Submitted, Awaiting Approval, Approved, Rejected Now since these will never change I was trying to decide the best way to implement them I can either think of a Status enum with the values and an int assigned where the int is placed into the status column on the table row.

Or a status table that linked to the table and the user select one of these as the current status.

I can't decide which is the better option as I currently have a enum in place with these values for the approval pages to populate the dropdown etc and setup the sql (as it currently using to Approved and submitted for approval but this is dirty for various reasons and needs changed).

Wondering what your thought on this were and whether I should go for one or the other.

If it makes any difference I am using Entity framework.

Posted: Aug 20 10 at 15:26

View 3 Replies!   View Related
WCF / ASMX :: Use Optional Parameterss In C# While Defining Service Contracts?
I mean can I do something like this:


and then implement it the same way as below

List<String> GetEmployees(String EmployeeId, String DepartmentID= "00")

I tried this, but it didn't work. Its always expecting DepartmentID when I tried to use invoke 'GetEmployees' using service reference.

Posted: Oct 01, 2010 05:13 AM

View 7 Replies!   View Related
Web Forms :: Possible To Have A Master Page For All Pages As Well As Defining Different Meta Tags
Right now all my pages inherit from a single master page which contains the main menu links and so on.. My problem is that I am not able to define meta tag descriptions inside every single page because they all inherit from the master page.

Posted: Nov 16, 2009 11:09 PM

View 2 Replies!   View Related
Forms Data Controls :: Defining The Series Parameters For An MS Chart?
I need to defining the Series parametersfor an MS Chart.

Using the sample data below is it possible toset the X & Y value types for a graphwith alldays forthe month on the X axis and the total number of visits for each day on the Y. Are MS Charts capable of auto generating the X axis based on the extents of the data dates as well a counting the daily instances?


Posted: Feb 25, 2010 01:17 AM

View 1 Replies!   View Related
C# - How To Load External Data Files Without Defining Path Explicitly
I have a C# assembly that loads external files. This assembly is used by website. The following is the code that loads the data files

string dataDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"data"); filePath = Path.Combine(dataDirectory,_fileName);

The component works fine in a windows app, but when I tried to use it in an website, it fails as the site could not find the data files. And it gives me the following error:

C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Filescmictranslatorsite20a8eddd864b2575assemblydl35bd4a35e8c6f79b6_98eccb01datafile.txt

Posted: Mar 27 at 18:23

View 1 Replies!   View Related
AJAX :: Defining Minimum And Maximum Range In One Slider Control?
I want to define Minimum and Maximum values in slider control. In slider control examples there is only one value in slider as in [URL]

Posted: Jan 10, 2011 09:57 AM

View 1 Replies!   View Related
Security :: Use Membership Provider In Forms Application Without Defining An App.config?
I have a small windows forms application that uses the membership provider that is defined in my app.config file. I want to get rid of my app.config file and initialize the membership provider completely from code. The reason behind this is because I want to be able to dynamically connect to different databases containing user tables and I want the user to be able to enter the desired database information into a text box at run time. Is this possible or is it required that I have an app.config file?

Posted: Feb 17, 2011 07:57 PM

View 1 Replies!   View Related
Web Forms :: Want To Support Defining Property When Declaring The Instance Of This User Control
I created user control. It exposes string[] public property (it may be List<string> or whatever). I want to support defining this property in aspx code, when declaring the instance of this usercontrol. Something like this:



Posted: Jun 10, 2010 09:00 PM

View 3 Replies!   View Related
What Are The Main Differences Of Defining A Control Statically Or Creating It Dynamically On Page Load
I am working on a project which creates controls dynamically for a form in the page_load event, loads in their current values from the database and saves their values (using FindControl) when the user clicks the continue button. When I added a control statically in the .aspx page and followed their same procedure of loading the value in the page load and saving it on the button press I found that the value would not save correctly. It seems that it wouldn't save because the click event fires after the page_load, so the page_load of the post back reverted the value and the user entered value was not saved.

The strange thing is that by changing the control to be dynamically created just as all the other controls on the page and keeping the loading and saving the same it now works. Even though the page load still creates the control with the old database value. It seems like a very fundamental asp .net feature here but i'm just unclear as to what is going on. I suspect it is to do with the timing of creation and maybe when the view state kicks in.

Posted: Sep 13 10 at 5:34

View 4 Replies!   View Related
MVC :: 2.0 Messing Up Routes In ARR 2.0
Ihave a server that has been using ARR 2.0 on IIS 7. I recently added MVC 2.0 to my ASP.NET site. After adding it the ARR routes return the following error: The virtual path 'null' maps to another application, which is not allowed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The virtual path 'null' maps to another application, which is not allowed. Source Error:


Stack Trace:


In my web.config I can remove the modules attribute runAllManagedModulesForAllRequests and the ARR works, but it makes the MVC routes stop working.

Posted: Dec 28, 2010 09:27 PM

View 2 Replies!   View Related
MVC :: Caching Routes Using IIS 7
We're trying to add caching to our MVC application using the IIS 7 Caching Module. However, the problem that we're running into is that the IIS 7 Caching module asks that you provide a file extension when you register a new cache rule. Since this is MVC, there is not file extension, just routes. Does anyone know if it is possible to use IIS 7 caching for MVC? We realize we can use the caching features built into Asp.Net, but we curently would prefer to control the caching at the web server.

Posted: Nov 16, 2009 04:15 PM

View 1 Replies!   View Related
MVC :: Routes Error In 2 RTM
Icreated an MVC 2 RTM Project and created 2 Areas (Admin and Applicants) Thecode belows was added into the global.asax: AreaRegistration.RegisterAllAreas(); I also ensured that duplicate Controllers were managed as i havea homecontroller in the root and the Admin Area. The code used was; new string [] {"MyAppName.Controllers"} This too went into the global.asax The error i got is below; A route named 'Applicants_default is already in the route collection. Route names must be unique. Parameter name: name how to resolve this?

Posted: Apr 03, 2010 11:31 AM

View 6 Replies!   View Related
MVC :: ViewBag And Routes (3 - RC2)
I am having an issue with MVC-3 generating outgoing routes for me. This is the address of the page I am on for both scenarios: [URL] Here are the map routes:


Scenario 1:
From the controller:
From the view:

The resulting link that gets created. [URL] If I change the controller code to read as follows:


I didn't make any changes in the view, only added those two lines to the controller and the following link is created: [URL] What am I missing here?This is consistent behavior, I was able to reproduce this in other areas of my application.

Posted: Dec 18, 2010 03:58 PM

View 4 Replies!   View Related
MVC :: Looking For Best Practices With Routes?
I'll explain my scenario to make easier to understand where I want to get to. I need to add few forms to my application. These forms are insurance inquiries and will be posted to a third-party server. So I mainly need to display them and when the user click Send, I don't need an Action to handle these forms, because they will be posted to another server.Now let's make things more complicated. I have three types of forms:

- Insurance Forms

- Claim Forms

- Surgery Inquiries Forms

The Insurance Form has 3 different forms:

- Insurance: Corporate Health Insurance

- Life Insurance

- Private Health Insurance

I want to make them SEO friendly, like this (pay attention to the dashes "-"):

- (THE FORM) etc...

I can easily create three controllers:

- Insurance - Claim - Surgery

Where the ActionResult Index() is the STATIC PAGE WITH INFORMATION. OK! And each controller will have ActionResults like these:

- corporate_health_insurance (Insurance Controller)

- life_insurance (Insurance Controller)

- private_health_insurance (Insurance Controller) etc..

Everything perfect, besides the fact I'm too picky and I don't to use underscore "_" in the URLs. I need to use dash "-" instead. I can't use dashes "-" for the Action names... but I can easily create a new route like this:


This solution fix my problem. I just wanted to know if this is the best thing to do. What do you think guys? Is it ok to map a new route just to make me (and my client) happy, and ignore the original? What do you think about the performance?

Posted: Nov 11, 2009 08:53 PM

View 3 Replies!   View Related
MVC :: How To Change Language Of Routes
I'm devoloping a website that is multilanguage, and i want the routes to change with the lenguage too, not only labels, controls, etc.

Let's say I have a CustomerController with an Index Action. To access it in english the url is Customer/Index, but if is spanish for example i want Clientes/Indice.

I'm thinking in something like having a resource (or many) with the translations of controllers and actions and override the method that matches the url with the controller.

Posted: Jul 16, 2009 10:24 AM

View 1 Replies!   View Related
MVC :: Spaghetti Routes In Right Order
I am having difficulty with my routing. I am trying to achieve the following pattern

1. ~/ : Lists all products
2. ~/Page2 : Lists all Products on page 2
3. ~/Categoryname : Lists Products in a particular category
4. ~/Categoryname/Page2 : Lists Products in a particular category on page 2
5. ~/Categoryname/ProductName : Details of a product in a particular category
6. ~/Admin/SomeView
7. ~/SomeView

I have provided code below with explanation of problems.

1. This route seems to work fine
routes.MapRoute( null,
"", // Only matches the empty URL (i.e. ~/)
new { controller = "Products",
action = "List", category = (string)null, page = 1 } );

2. This route seems to work fine
routes.MapRoute( null, "Page{page}",
// Matches ~/Page2, ~/Page123, but not ~/PageXYZ
new { controller = "Products",
action = "List", category = (string)null },
new { page = @"d+" } // Constraints: page must be numerical );

3. This route seems to work fine
routes.MapRoute( null,
"{category}", // Matches ~/Bouquet new {
controller = "Products",
action = "List", page = 1 } );

4. This route seems to work fine
routes.MapRoute( null,
"{category}/Page{page}", // Matches ~/Bouquet/Page2
new { controller = "Products",
action = "List" },
new { page = @"d+" } // Constraints: page must be numerical );

5. Problem route - this currently uses the following pattern ~/Categoryname/Details/Id, not what I want
routes.MapRoute( null,// Route name
"{category}/{action}/{id}",// URL with parameters new {
controller = "Products", category = "", action = "Details",
id = "" }, // Parameter defaults
new { id = @"d+" } // Constraints: page must be numerical );

6. This works fine for pattern 6, but not with pattern 7
routes.MapRoute(null, "{controller}/{action}");

I probably don't have these in the right order in the route collection. I can provide my Actionlinks if needed.

Posted: Sep 09, 2009 10:42 PM

View 1 Replies!   View Related
C# - Routes With Multiple Arguments In MVC 3?
I am trying to set up dynamic routes in an MVC app, and I have this so far...


And that is working great for now, the only issue I am having is that I would like to have the ability to specify a comma delimited list of optional arguments in the database that I could pull out like...

Array optParams = rdr["parametersOpt"].ToString().Split(',');

But I was not sure how to stick those params into the route object properly. Could just be a minor C# syntax I am not familiar with.

Posted: Jan 19 at 16:25

View 2 Replies!   View Related
MVC :: How To Organize More Complex Routes
I understand the basics of setting up routes, I am trying to get a handle on how to organize more complex routes. Does the Route name do anything? I havn't seen a place it's actually used. If I havethe route: controller/action/id/paramA/paramB/paramC. ParamA-C could be defining multiple parameters so First/Last/Zip or Phone/Zip/Birthday. Is it common practice to name the additional parameters with a generic namelike paramAvs trying to differentiatea separate route for each?

Lastly, if you have multiple sites/functional areasin 1 site, lets say the site, each area MVC, Ajax, Forums ectwere all different functional areas. Is it best to create a differentgroup of routes such as hard coding the controller like:


or is there a better way? What I am running into is 1 piece of the site overriding the other routebecause of the number/type of parameters.

Posted: Mar 12, 2011 11:14 PM

View 5 Replies!   View Related
Copyright 2005-08, All rights reserved