C# - Get Url From RouteTable.Routes Collection By Key?
Oct 14, 2010How to get url from RouteTable.Routes collection by key?
View 2 RepliesHow to get url from RouteTable.Routes collection by key?
View 2 RepliesIn my Global.asax file on Application_Start I create a certain number of routes in RouteTable.Routes by looping through a list of web pages collected from a database. This works fine, all routes are created and function as required. But in my web application the user can modify the database and therefore the collection of web pages. This means that during the life cycle of the application some of the routes become invalid, and new routes should be added.
What I wish to do is: The moment the user changes something to the web pages collection, I would like to clear the RouteTable and reload it by looping through the (modified) web pages collection again.
Unfortunately the Application_Start in Global.asax is ran only once, namely at the beginning of the application. I tried moving it to Session_Start which results in undesired behaviour due to the RoutesTable being static.
How do I give my user the ability to change the web page collection on-the-fly whilst having the static RouteTable remain 'in-sync' with it?
Edit
At the moment I do something like this (pseudo-code):
[code]....
The problem is that during the life cycle of the application users can add/modify/delete records in the webPageInfos, how do I update the RouteTable with these changes?
I'm trying to prevent direct file requests from being accepted, and have tried this:
[Code]....
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?
I have a page with 4 option query string. I wan to show SEO friendly URL with all four query string. I have configured as follows in global.asax file:
routes.MapPageRoute("commercial", "real-estate/commercial/{state}/{dist}/{location}/{seoTitle}.html", "~/Commercial.aspx");
the page can be display like:
- [URL]
- [URL]
- [URL]
- [URL]
So my question is, shall I need to configure separately for each link and that this will work for above said scenario?
I'm trying to figure out how to enumerate the URLs of Routes in the RouteTable.In my scenario, I have the following routes defined:
routes.MapRoute
("PadCreateNote", "create", new { controller = "Pad", action = "CreateNote" });
routes.MapRoute [code]...
In other words, if my site is mysite.com, mysite.com/create invokes PadController.CreateNote(), and mysite.com/foobaris invokes PadController.Index().I also have a class that strongly types usernames:
public class Username
{
public readonly string value;[code]....
In the constructor for Username, I would like to check to make sure that name isn't a defined route. For example, if this is called:
var username = new Username("create");
Then an exception should be thrown. What do I need to replace //... make sure 'name' isn't a route URL off root with?
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:
[Code]....
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)
[Code]....
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.
I have a list of objects that I want to bind to a gridview. Creating that list and binding it works fine for most of the public properties in that list.
There are some objects contained in each of those objects... for instance there is an Address object.
object.Address.Line1;
object.Address.Line2;
When I bind this to my gridview, I have no issues with stuff like object.DateRegistered, but how can I access things like object.Address.WhatEverProperty? I always get this error:
"A field or property with the name 'xxx.xxxx' was not found on the selected data source."
I want to know that how i use the collection class for storing some data and save it letter in the data base.
View 4 RepliesI have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution.
These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:
(in case of updating textbox.text):
[code]....
However the text property of the textbox does not actually get updated. I'm mainly trying to avoid having to manually do textbox.text = somestring for each one of my textboxes every time I have to update them.
I know that if I have set a cookie on a previous request, it will show up in my Request.Cookies collection. I want to update my existing Cookie. Are the cookies from my Request.Cookies collection already copied to my Response.Cookies collection? Do I need to add a new cookie with the same key using Response.Cookies.Add(), or do I need to use Response.Cookies.Set()?
View 1 RepliesI'm using HttpModule to capture requests to the web server. Before processing the page I'd like to check the values contained in some keys of the Request.Form collection and according to some logic change if necessary. I'd like to do this when BeginRequest event is fired. The problem is that the Request.Form collection is readonly.
View 4 RepliesI have 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:
[Code]....
Stack Trace:
[Code]....
In my web.config I can remove the modules attribute runAllManagedModulesForAllRequests and the ARR works, but it makes the MVC routes stop working.
I created an MVC 2 RTM Project and created 2 Areas (Admin and Applicants) The code belows was added into the global.asax: AreaRegistration.RegisterAllAreas(); I also ensured that duplicate Controllers were managed as i have a 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?
View 6 RepliesI 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:
[Code]....
Scenario 1:
From the controller:
[Code]....
From the view:
[Code]....
The resulting link that gets created. [URL] If I change the controller code to read as follows:
[Code]....
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.
I am trying to set up dynamic routes in an MVC app, and I have this so far...
[Code]....
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.
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 have the 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 name like paramA vs trying to differentiate a separate route for each?
Lastly, if you have multiple sites/functional areas in 1 site, lets say the asp.net site, each area MVC, Ajax, Forums ect were all different functional areas. Is it best to create a different group of routes such as hard coding the controller like:
MVC/action/id
Ajax/action/id
Forums/action/id
or is there a better way? What I am running into is 1 piece of the site overriding the other route because of the number/type of parameters.
I been looking for hours on the web to find a good tutorial where I can do a database localization with mvc 2, I can't find any its all resource files. So I'm trying to reach out to you guys and see if you got any links, books or suggestions on this topic? I would love for it to be url routes based localization but that I can figure out somehow i think.
View 10 RepliesI'm creating a new ASP.NET MVC 2.0 web application that will have 5 main pages:
- Home
- Services
- Contact Us
- Terms & Conditions
- Priva
We are working on a project which has lots of routes that can be changed on-the-fly or new routes can be added dynamically. What are the best practices about managing lots of routes and adding routes on-the-fly without recompiling? Reading-Writing from-to database or from Xml Document in Application_Start?
View 4 Replies how to do routing. My problem basically relates to "logged in" and "logged out routes" and having both as "/".
i.e. I have home/index for logged out user which appears as "/" but this has got me confused as to how I can have home/home for logged in user and still have "/".
I keep getting 127.0.0.1/home/home
I could modify like 127.0.0.1/home - but I want it like "/". My confusion relates to the fact that the "/" [127.0.0.1/] is bound in the routes collection to home/index.
how I can modify the routes dictionary (which will be binded ONCE at the start) so that the "/" can be shared for logged and non-logged users ?
I'm looking to add more organization to my Views folder by adding subfolders to the existing structure.
Views
Configuration
Controller
View View
Controller
View
Controller
View
Controller
View
So in order to add the "Configuration" subfolder, I attempted to add a route to the routetable:
[Code]....
This results in a 404 error.
All of the similar posts I've seen on this site and the web have to do with adding "areas" which don't seem to be applicable in the MVC3 arena.
I am using .NET Page Routing (not MVC) to get pretty URLs (or at least removing the file extensions) on my site.On my search page, when a user searches for "stuff" it redirects then to /search/stuff for the results. However when I put in something like "stuff yes:" it gives me a HTTP 400 Bad Request Error.
I tried using javascript to encode the search value before being submitted, and confirmed that "stuff yes:" was converted to "staff%20yes%3A", yet when it performs the routing redirect, in the URL it shows "staff%20yes:" and causes the bad request. Why is it not saving the encoding for the typically illegal characters and how can I make it so?
I have an Asp.Net website which should have a variable as a string in the url.
The content of the website changes depending on the year. the idea is to have this year in the url in a clean way.
http://localhost/YEAR/index.aspx
I have done this in MVC with routing, but i have no idea how to do it in asp.net I basically need just 1 route I guess. so all URL's will be as they were before (index.aspx, ...) basically in stead of having ?year=2011 behind EVERY url in the website i'd like to have this value in the route.
I'm reading about URL routing at How to: Define Routes for Web Forms Applications and there's something in the example I don't understand. If you look at the example provided below,
routes.MapPageRoute("", "SalesReport/{locale}/{year}/{*queryvalues}", "~/sales.aspx");
How can I have multiple routes in a single request at global.asax? Error "The incoming request does not match any route."
[code].....