.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ASP.NET MVC2 Custom routing with wildcard or free text url

Posted By:      Posted Date: September 28, 2010    Points: 0   Category :ASP.Net

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.

This must be possible someho

View Complete Post

More Related Resource Links

Load balancing and Custom Filters in WCF 4.0 Routing Services

Hi, Couild someone please guide me to various ways of achieving load balancing using Router Service. i tried seeing few Blogs and tried to understand the round robin concept and the custom filters conceptr. but i m not able to see any specific site which would guide me on various examples of custom filters .And round robin seems a bit complex. http://blogs.msdn.com/b/routingrules/archive/2010/04/14/load-balancing-at-the-routing-service.aspx The above link gave me some insight  . is there any othe way of achieving load balancing other than Round robin. I did go through the samples of Routing services in WCf training Kit Thanks

Wave to Text - Need help with custom grammar

I created a wav to text conversion using a ISpeechRecoContext and it works, but it is not precised. I was hopping to add a custom grammar to it but im not sure how to. Any ideas? Here is a WPF MainWindow.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.Win32; using SpeechLib; namespace WaveToText { public partial class MainWindow : Window { private ISpeechRecoContext WaveRecognizer = null; private SpFileStream InputWAV = null; private ISpeechRecoGrammar Grammar = null; public MainWindow() { InitializeComponent(); } private void ExitButtonClick(object sender, RoutedEventArgs e) { this.Close(); } private void ConvertButtonClick(object sender, RoutedEventArgs e) { ResultTextBox.Text = ""; OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "Select a Speech file"; dialog.Filter = "Wave Files (.WAV)|*.wav"; // Filter files by extension dialog.InitialDirectory = Environment.CurrentDirectory + "\\Content"; Nullabl

MVC2 UpdateModel method, with custom ViewModel and cruicially.... PartialViews.

Hi, not usually one to ask for help but 2 days on this and not really getting anywhere. I have a view that gets posted back to my controller and I can call updatemodel pass in the FormCollection and everything in the view gets updated and works great etc... The problem is, this view contains several PartialViews that I just can't seem to get the UpdateModel helper to update. All this stuff is strongly typed, I mean my overall viewmodel has properties that expose the data to my partialviews. (just for clarity see below code, "Model" has a property called "AreaListViewModel", which has a property called Areas. "AreaList" is the partialview/usercontrol). <% Html.RenderPartial("AreaList", Model.AreaListViewModel.Areas); %> I'm convinced it is either something to do with the way I add the data to my partialview, like HtmlTextBoxFor syntax. OR the UpdateModel syntax. As mentioned I get my form data back as a "FormCollection". [AcceptVerbs(HttpVerbs.Post)]public ActionResult Details(int Id, FormCollection formData) Many thanks for any help/pointers.        

Can't Get Text From Custom Wizard Step


I'm trying to get the text values from each textbox in a custom created createuserwizard step however i keep returning null for each textbox however the default step & text boxes (ie. UserName, Password, Email, etc, etc) i can get the text value with no problem



            <asp:WizardStep ID="CreateUserWizardStep0" runat="server">

custom validator firring on text changed


hi all i have a custom validator i have written a javascript method for this validator;

this validator has been pot on a textbox that has auto post back is true .... now this validation  fires when the post back happens...

i dont want it to fire on the post back but only on button click

please suggest 

thanks in advance 


ASP.net free text search issue for "C#"


In my ASP.net application I have used index server utility to search specific text from word/text files.

For this functionality I have used index server and configured folder. After implementation of this program this was running fine but after some time user reported they can not find keyword "C#" or any word with "#". I think I should share my experience and solution with other developer who may also faced or facing this issue.

Use the following code and it will work.

"Desc" is the text box name and searchstr is the search string paased to index server to search from files.


Desc.Text.contains("C#") Then

searchStr = "C#"


searchStr = Desc.Text.ToLower()


End If

Implementing custom ValidationFor to show an error icon with a tooltip instead of just text for c


I got the problem that my implementation (see source below) only shows the validation error message after server side validation an NOT

after clientside validation! My questions is, how can you extend or implement to show the validation error message also on client-side validation.

Unfortunately I have not found any other info source about this subject, so any help will be very much appreciated!

 public static string ErrorMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
            string modelName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression));
            FormContext formContext = htmlHelper.ViewContext.FormContext;

            if (!htmlHelper.ViewData.ModelState.ContainsKey(modelName) && formContext == null)
                return null;

            ModelState modelState = htmlHelper.ViewData.ModelState[modelName];
            ModelErrorCollection modelErrors = (modelState == null) ? null : modelState.Errors;
            ModelError modelError = ((modelErrors == null) || (modelErrors.Count == 0)) ? null : modelErrors[0];

            if (modelError == null && formContext == null)

Question about custom routing


Hi all,

I have to admit in advance that I'm quite new to MVC, I've been going through the resources at asp.net/mvc, but I was wondering if you guys could help me with something.

I have been asked to create a ASP.NET version of an existing PHP website, this website has a huge number of existing links to it in a particular format, which I have to replicate in due to the amount of work to change all the existing links would be far too much.

The format of the existing links is;


My attempt at creating a custom route doesn't appear to be working. What I have done is change the RegisterRoutes method in Global.asax.cs file to be;

public static void RegisterRoutes(RouteCollection routes)

        new {controller="ExistingLinkController", action="Index"},
        new {LinkId = @"([A-Za-z0-9]{14})", Title = @"([A-Za-z0-9_-]*)

How can I add a SharePoint Rich text editor in my custom application page?


I want to have a richtext editor in my custom application page.

Can I use the richtext editor  bulit-in in SharePoint?

I tried add this code in my aspx but it doesn't render the control but throw a error

<SharePoint:RichTextField ID="DefaultValue" runat="server" ControlMode="New" FieldName="Title"></SharePoint:RichTextField>

Anyone helps?

Small problem with displaying custom calendar cell text from db in Safari


using VS2010

I'm using the calendar control to create a simple event calendar. I want to add a small bit of custom text just below the date of any cell that contains an event on that date.

The code:

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
      string connString = ConfigurationManager.ConnectionStrings["CalendarConnectionString1"].ToString();
      SqlConnection myConnection = new SqlConnection(connString);
      SqlDataAdapter myAdapter = new SqlDataAdapter("GetEvents", myConnection);
      DataSet myDataSet = new DataSet();
      myAdapter.Fill(myDataSet, "Table");
      //If the month is CurrentMonth
      if (!e.Day.IsOtherMonth)
        foreach (DataRow dr in myDataSet.Tables[0].Rows)
          if ((dr["Date"].ToString() != DBNull.Value.ToString()))
            DateTime dtEvent = (DateTime)dr["Date"];
            if (dtEvent.Equals(e.Day.Date))
              e.Cell.BackColor = Color.MediumAquamarine;
              Label label = new Label();
              label.Text = "</br>";
              label.Text += dr["Title"].ToString();              

Parsing Free Text with Ordered Lines


What is the best way to parse the ordered text as given in the following T-SQL script? Thanks.

USE tempdb;
DECLARE @EnglishText TABLE (ID INT IDENTITY(1,1) PRIMARY KEY, EnglishText varchar(128))
INSERT @EnglishText (EnglishText) VALUES
('New York City is on the Atlantic'),
('Objct: New Jersey is on the Atlantic Ocean. '),
('Atlantic City is on the Atlantic Ocean. The city''s '),
('famous boardwalk is lined with casinos'),
('Yellostone is a National Park.'),
('California is on the Pacific Ocean.'),
('Quito is the capital of Equador.'),
('Objct: Mandalay Bay Hotel Casino is in'),
('Las Vegas. It was the host for a number'),
('of Microsoft conferences.'),
('Mamma Mia is a Broadway musical playing in'),
('the Winter Garden theatre.'),
('In the Heights is a modern'),
('Broadway musical.'),
('Objct: Newport, RI is the "capital" of sailing'),
('on the East Cosst.'),
('It has a famous seaside walk with 100 year-old'),
('Newport''s St. Mary''s church was'),
('the wedding location of Jacqueline Bouvier to John Fitzgerald Kennedy on September 12, 1953.'),

Removing standard text from custom feedback process email notification


My workflow has a Start Feedback Process action, which contains some pre-defined instructions. One of my instructions is to use a particular link to open the workflow history page – I have added this to force the user to open the form via the workflow history page (we're using Forms Services) because the email’s default link opens the form in the InfoPath client, not the browser. It also allows the user to be returned to the page where they will complete their workflow task (we're trying to make navigation as easy for them as possible).

Although I have defined my own set of instructions, the email notification I receive includes some standard text that links to the InfoPath form’s xml file. I don’t want users inadvertently clicking the “To complete this task…” link at the bottom of the email and having the form open in InfoPath. Here is an example of the email I’m referring to:


Routing MVC2


I have a url


 I wanted to route the and make it 

  http://localhost:2151/Classified/London/                    here  cid =1 ,=> London

To accomplish this I written this code in Global.asax

            new { controller = "Classified", action = "citycatadd", id ="city"  }  );

and this code in HTML

<%= Html.ActionLink(objaddcity.city1, "citycatadd"

How to custom Rating Scale field to add more range text in survey on MOSS 2007


When we use the rating scacle fied to create question in survey. You can only set three range texts for each question. Is there any way to allocate a range text for each range ? Such as below :

                                 low             normal          high       important        very important

                                 1                  2                  3               4                     5

First question about ...?  


Thanks all your help !


Creating custom Intellisense-based text editor like Pex for Fun


We would like to create a custom text editor which allows our end users to enter .Net code that hooks into our .Net API with Intellisense similar to how it is done on the Pex for Fun website: http://www.pexforfun.com/

Is there a way to build a custom control text editor (or use a 3rd party free or purchased control) that supports .Net Intellisense  in the same way done by Microsoft on the Pex for Fun website?


Can you custom format a single sitemapnode based it's text, url or level (submenu)?


The title pretty much states the question.  I have a menu inside my asp.net master page.  This menu pulls from  a web.sitemap file.  I have a css file that formats the individual nodes.  However, I want to format the menu headers a certain way while the submenu's are different.  Namely, I want to put a small image before all the submenu points while not the main sitemapnodes.  So far, I can use css to put the image infront of every node.  But I haven't been able to differentiate between the nodes.  The main node has a blank URL instance.  I thought I could use that in the C# code but I haven't been able to .  Could someone give me a link or show some code on how to do this?  Thanks.

Rich text box functionalities in custom webpart


Hi All,


I have created a custom webpart with a inputformtextbox using the below code snipe:


InputFormTextBox iptFormTbx = new InputFormTextBox();

iptFormTbx.Rows = 10;

iptFormTbx.RichText = true;

iptFormTbx.RichTextMode = SPRichTextMode.FullHtml;

iptFormTbx.TextMode = TextBoxMode.MultiLine;

iptFormTbx.AllowHyperlink = true;

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend