.NET MVC2 Custom Routing With Wildcard Or Free Text Url?
Sep 28, 2010
I have a requirement to add specific functionality to an asp.net mvc2 web site to provide addtional SEO capability, as follows:
The incoming URL is plain text, perhaps a containing a sentence as follows
"http://somesite.com/welcome-to-our-web-site" or "http://somesite.com/cool things/check-out-this-awesome-video"
In the MVC pipeline, I would like to take this URL, strip off the website name, look up the remaining portion in a database table and call an appropriate controller/view based on the content of the data in the table. All controllers will simply take a single parameter bieng the unique id from the lookup table. A different controller may be used depnding on different urls, but this must be derieved from the database.
If the url cannot be resolved a 404 error needs to be provided, if the url is found but obsolete then a 302 redirect needs to be provided.Where the url is resolved it must be retained in the browser address bar.
I have had a look at the routing model, and custom routing and can't quite work out how to do it using these, as the controller would not be predefined, based on a simple route. I am also unsure of what to do to provide 404, 302 back to the headers also.Perhpas I need a custom httpmodule or similar but going there went beyond my understanding.
If you cannot turn on wildcard mapping for IIS (shared hosting) or can't be bothered (lazyness) can you still use ASP.Net routing if your routes end in one of the "known" asp.net extensions...like ending all routes with .ashx, .aspx etc?
From Chris Cavenagh's blog, could his examples of:
[code]...
I'm presuming so as his last route is Default.aspx, but he hasn't included any route data with that...Is there a better way? Provided this works, it looks like the best as if the application is moved or wildcard mapping can be turned on, only the routes need to change...
I am using FTB on my aspx page. is there any way I can have Toggle Full screen feature in FTB, is this feature availble in FTB? it is available on TinyMCE, but I don't want to switch to TinyMCE since I am already using FTB in most of the pages in my application.
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:
Whilst my validation is successful/fine with this control (ValidationMessageFor works) I have been unable to find how to highlight the control when validation fails (e.g. with a TextBoxFor the textbox border goes red if validation fails)
Does anyone know how I can add this behaviour with a custom editor template?
This value, MembershipService.MinPasswordLength, is zero (0). Obviously, this is coming from my class. I can't have a set because the abstract class has this as a read-only property.Why doesn't the MembershipProvider read this value from the Web.Config? What am I missing?
When Iuse FTB in a normal web form I am having no issues. However when I create a master page then a web form that uses that master page I get the following error when pulling text from the FTB control
A potentially dangerous Request.Form value was detected from the client (ctl00_ContentPlaceHolder1_FreeTextBox1="<b>My TEXT</b>")
I get this error only when it uses html tags and only when its in a form that uses a master page.
I am working on an MVC2 application and want to set the maxlength attributes of the text inputs.
I have already defined the stringlength attribute on the Model object using data annotations and it is validating the length of entered strings correctly.
I do not want to repeat the same setting in my views by setting the max length attribute manually when the model already has the information. Is there any way to do this?
Code snippets below:
From the Model:
[Required, StringLength(50)] public string Address1 { get; set; }
I have an ASP.NET 4 MVC2 multi-language application and I need the same HomeController to response ДОМОЙ as well.Our application has 12 Controllers and should support 9 different languages.The optimal solution would be to override some FindControllerByName & FindViewByName, but I can't find such functions. Do any of you guys know how can I achieve such a behavior?
void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { routes.Add("BikeSaleRoute", new Route ( "bikes/sale", new CustomRouteHandler("~/Details.aspx") )); }
here when we type eg:[URL] it go to details.aspx now i want instead of bikes/sale that define here it read Behcode column from DB and when my user type their becode like this [URL] it go to details.aspx
I have a problem with my site, and I'm using .net 4, web form routing
I have this route ,routes.MapPageRoute("JobPreview", "jobs/{jobId}/{pg}/{Position}", "~/default.aspx")
so, this page is working fine http://www.jobsagents.com/jobs/24651/1/automation-qa-engineer
If we remove the last segment of this url, it should be redirected to the custom 404 not found page, but in the deployment server it redirects to the default IIS error page for 404 errors
http://www.jobsagents.com/jobs/24651/1/, on my local machine it's ok, and shows my custom error page.
If we remove the last three segments of the url http://www.jobsagents.com/jobs it works fine on the deployment server.
I am using ASP.NET 4.0 Web Forms. I learned that, in order to optimize my Web Application for Search Engine, I must implement custom 404 page. But the way Microsoft tell us to implement custom 404 (within Web.Config file), that is not good for SEO. Microsoft says,
But when the page is not found, IIS issue 302 redirect to Page-Not-Found.aspx page which is not good. So, I implemented custom 404 page using Routing technique that is available in ASP.NET 3.5 SP1 and 4.0. I used the following router in Global.asax page
I've have been searching the web for weeks trying to find a solution for my application buttons. What I want is a control that will display the various buttons for my application from the splash page down to the save/submit. The control needs to be able to handle the following:
Image + textset Text Location (top, left, bottom, etc) Rollover Image ChangeBorder size and colorbackground color set Heightset width I have the rollover affect working. Below is the code for the imagebutton with rollover
My students are working on an ASP.net VB application for a Web Programming competition and we are having problems with a page where we want an URL string to return all values from our database.
Here is the page:
[URL]
If you use the jobs by category menu on the left side, if you select a job category (ie retail) it will pull up all the jobs from that category. By using a query in the URL like this:
[URL]
What we need is the URL that would show all jobs regardless of the category. I'm not sure how to do this with asp.net VB. I'm sure it's probably not all that hard, we just don't know the syntax to make it happen.
created a Custom Textbox Control that is intended to be a "masked date" textbox, so that I can handle different ways a user might enter in a date and make it work no matter what.I did this by creating a custom control with 3 separate Textboxes one for month,one for day one for year,then do some handling for different things that could be entered and it would all work.
The problem I am having is,when I add this control to the page,if I do an alert to check the Text value of the custom control it just gives me "[ServerControl1]" even if I enter in a date.
I tried doing an AutoPostback after entering so that it would refesh the Viewstate to have the values of the textboxes but the control doesnt seem to actually postback, even though I have it enabled.accessing the Textbox value after someoen has entered a date?first custom control I have created and have been using google.