Enumerating .NET MVC RouteTable Route URLs?
Dec 14, 2010
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?
View 1 Replies
Similar Messages:
May 10, 2010
I have a simple custom membership provider. And i have a roles table also in my database with 2 roles in, User and admin. I dont think i need to implement the roleprovider as this will be overkill for what i need.
How can i modify the validate user method to route users to one URL and admin to another?
Can i put in a If statement to say If role = admin go here after a user has been validated?
[Code]....
View 3 Replies
Nov 16, 2010
i have a function that pulls URLs from various web resources. needless to say some are full valid URLS and some are relative as per the HTML of the page. below is my asp.net/ c# logic i derived for examining the URL and then generate a full usable URL from whats pulled from the site...
NOTE:
origianlurl is the full url of the first searched page, and relativeUrl is a url found within the searched page (it can be a full www.site.com or a /contactus.html)
private string ResolveRelativePaths(string relativeUrl, string originatingUrl)
{
if (relativeUrl.StartsWith("http") || relativeUrl.StartsWith("www"))
return relativeUrl;
if (relativeUrl.StartsWith("/"))
{
//get main url something.com
[code]...
View 1 Replies
Jan 11, 2011
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?
View 2 Replies
Oct 14, 2010
How to get url from RouteTable.Routes collection by key?
View 2 Replies
Feb 5, 2011
In 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?
View 2 Replies
Jun 30, 2010
This error never happens before in my machine since 7 months of using it. [:(]
"There was an error while enumerating services on local machine: Active Directory Services cannot find the web server. A possible cause for this is an incompatibility between versions of Internet Information Server (IIS) on the client and the server. Another possible cause is that IIS is not installed on the local machine, or the user identity under which you are running may not have permissions to view websites on this machine. To view websites on this machine, make sure that you run Visual Studio as administrator. On Windows Vista computers with IIS installed, make sure that IIS Metabase and IIS 6 configuration compatibility feature is enabled."
I'm trying to add back a webservice (localhost) after deletion. And suddenly I'm getting the above error.[:(]
The error's suggested tip is to install IIS but I did not install IIS since then in my machine because VS2010 built-in server do just fine. Should I install IIS?
I also found this helpful tips but nothing works. [:(]
* Run Visual Studio with elevated administrator permissions
* Be a member of the "Administrators" group on the local machine
* Right-click the Visual Studio icon and select the "Run as administrator" option from the context menu.
View 2 Replies
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
Feb 14, 2011
As an extensibility option for my web application I would like to allow the user to add sections to it by simply making new folders and uploading files to them. So, for instance, if they created (in the webroot): /UserContent/StaticPages/First/Second/index.txt. Then in the main menu there would be a new menu point "First" with the submenu point "Second", which would lead to markdown-parsed version of index.txt. This way the user can upload any static menu points he wants (such as "About us", "Contact us", "Our Mission" etc.) Another extensibility point is that I would like them to add headers/footers to specific webpages in a similar fashion. I'm using ASP.NET MVC3, so there are pretty URLs, and it would be easy for the user to just create: /UserContent/Additions/Store/Categories/35/header.txt
And when someone opened [URL] the markdown-parsed header.txt would be prepended. This is simple for the user, and simple for me (I don't need to make sophisticated admin panels and WYSIWYG editors). However I'm worried about the performance. This scheme means that on each GET request I would need to scan the /UserContent/StaticPages folder and check for the existences of the header/footer files (several, because parent levels can have their header.txt/footer.txt as well).
I could cache the result, but then I have to manage the cache and the user will need to know that changes can take up to X minutes to display. Would this be a premature optimization? There won't be much data in those folders, so Windows will probably be able to easily cache their contents itself.
View 1 Replies
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
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
Feb 1, 2011
I have a user that when I attempt to enumerate her groups using either System.Security.Principal.WindowsIdentity.GetCurrent().Groups on user's computer
or System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups on the IIS server, I get a list of their old groups, not their new. I have checked the DC that they authenticate to and the ASP.NET page is running inside a SharePoint instance so the LogonUserIdentity most like is being provided from there Kerberos ticket.
Should I be looking up the groups directly from the AD instead of relying on the WindowsIdentity or LogonUserIdentity?
View 1 Replies
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
Feb 16, 2011
I want to rewrite something like this:
www.webaddress.com/article.aspx?date=150211&title=title-of-news-article
to this:
www.webaddress.com/150211/title-of-news-article
Even to achieve the first link above, I need to replace capital letters and non-standard characters like é with e, and replace spaces with hyphens. Is all of this possible using URL Rewrite Module 2.0 or might I be better off coding some ASP? I'm new to .net and may have to do something in classic if I struggle. And I only just get by in ASP...
I've tried some of the tutorials on the official IIS website and have got through a simple rewrite wizard, but replacing characters seems more complicated, and I'm sure some of the tutorials have errors in them...
View 6 Replies
Dec 16, 2010
I need to Encrypt the URLs in my ASP.NET MVC application.
Do I need to write the code in Global page in Route Collection to Encrypt all the URLs?
View 1 Replies
Feb 17, 2011
I have a application which uses intelligencia urlrewriter to rewrite urls into seo friendly urls. Blog engine is integrated in this application under subfolder but shares webconfig with my application. Application runs perfectly on development server, but when i publish it to 2008/IIS7 server urls links don't work. Links similar to following work
<rewrite url="^/Abc" to="~/abc.aspx" processing="stop"/>
<rewrite url="^/Abc_123" to="~/abc-123.aspx" processing="stop"/>
But links like following fail to redirect and i get 404 errors
<rewrite url="^/Abc/(.*/)" to="~/abc.aspx?id=$1" processing="stop"/>
<rewrite url="^/XYZ" to="~/xyz.aspx?cat=school" processing="stop"/>
Anything which has query parameters in aspx url fails. I'm not sure what is causing this error on 2008/IIS 7 server and not on my VS 2008 development server.
View 1 Replies
Feb 22, 2011
I am using asp.net and when I type a bad url manually(in the browser) it gives me: The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. I want a bad url that doesn't exist to be re-directed to the home page. How do I do this?
View 4 Replies
Feb 28, 2010
I am using the NerdDinner project to experiment with MVC. http://nerddinnerbook.s3.amazonaws.com/Intro.htmI have put an image map on the front page and cannot work out how to generate the urls for it.
[Code]...
View 1 Replies
May 2, 2010
if I choose without dash, when I try to access [URL] it will return a 301 to the link without dash: [URL] The question is, how can I do that with ASP.NET MVC?
View 3 Replies
Sep 2, 2010
I know the default routes in MVC include an id param which often maps to the identity of an entity as it's stored in the database. Now, often this is OK, but what about when you don't want someone to be able to manipulate it? Quite frankly, on many business apps this is very common. For example, you don't want someone to change the account number (not the best example, but you get the idea) in the URL for obvious reasons. So, you would need to validate the account number against the logged in user on every request. Obviously, that is not a realistic solution, and in webforms many people would store something like that in session. I am trying to rely on session very little in MVC, but aside from that would I just go old school and use hidden fields
View 2 Replies
Feb 23, 2010
What is the best way to implement friendly urls in asp.net 2.0 for example I have http://www.predatorsfc.org/BrowseThreads.aspx?ForumID=23 and would to like add the forum title to the url to make the url more user friendly ?
View 6 Replies
Aug 12, 2010
i want to convert my dynamic urls to static urls.
I dont have apache installed on my server so it cant be through .htaccess re-write.
Here is the example what i want :
[URL]
I want to change all odds.asp pages to static URLs.My previous posts and new posts too.
Here is my odds.asp file
[URL]
View 1 Replies
Dec 2, 2010
My site was working fine before I starting working on incorporating URL redirection/rewriting. I have tried to preface all the URLs for graphic images and navigate URLs with a tilde and a slash ("~/"). However, now that I'm using rewriting on many of my pages, if the number of folders in the URL is 2 or less (such as MyDomain.com/Title/Author), it finds the graphics files without any problems, like before. When I view page source, I see that the HTML is calling for relative URLs that start with "../../", which is why it works for 2 or less folders in the URL. When there are 3 or more folders (such as MyDomain.com/Title/Author/Category), then it doesn't display the graphics files.
why I'm getting these relative URLs and so the files are not displaying correctly at times?
View 7 Replies
Jan 6, 2010
I have a program that parser html and collecting urls. The problem is when checking for duplicates before I add them to an arraylist is that I cannot distinguish between types of the following format:
http://forums.asp.net/AddPost.aspx?ForumID=15
http://forums.asp.net/AddPost.aspx?ForumID=15/helloworld.asp
http://forums.asp.net/AddPost.aspx?ForumID=15/helloworld.asp/byeworld.html
Now if I captured the first url, how can I avoid collecting the next few since they are not technically duplicates.
View 2 Replies
Mar 25, 2010
I want a regex expression which only match extensionless url. In otherwords if an extension is present in url then completely ignore it.
/(.+)/(.+) this will match an URL both with and without extension.
www.site.com/sports/cricket should match
www.site.com/sports/cricket.aspx shouldn't match
View 3 Replies