views:

17

answers:

1

hello everybody

my site has many many routes. since the users can add or remove pages at will, i need a way to reregister the routes from time to time

at reregister i do not want to clear the whole route cache ("RouteTable.Routes.Clear"), but i would rather go thru the table route by route, and using a certain regex on its name, decide if to remove it or not.

after that i will reregister the specific pages that i need to

heres my code meanwhile

        For Each r In RouteTable.Routes
            If CType(r, Route).DataTokens("ConfigID") = ConfigID Then RouteTable.Routes.Remove(r)
        Next

after the first remove it throws an error "Collection was modified; enumeration operation may not execute."

thank you very much for your help!!

+2  A: 

It's not possible to get the route name of the route because the name is not a property of the Route. When adding routes to the RouteTable, the name is used as an internal index for the route and it's never exposed.

There's one way to do this.

  1. When you register a route, set a DataToken on the route with the route name and use that to filter routes.

The easiest way to do #1 is to probably write your own extension methods for mapping routes.

Haacked
hi. thanks. great idea. please c my code now. i now get an error "Collection was modified; enumeration operation may not execute." this err is familiar so i thought ill just build a new routecollection and feed it to the routetable, but its readonly. so what can we do?
Yisman
hi. can anyone help me here?
Yisman