A Little more on the MVC Routing

Published 6/22/2009 by Dave in asp.net
Tags:

Couple of links (Which I need to have a further read of)

Legacy Url Routing - converting your ASP.net application to a MVC, how to route the old aspx page to redirect to the MVC required view.

Asp.Net Routing Debugger - allows you to type in URLs and it shows which routes match it (nice :) )

three Common ASP.NET MVC URL Routing Issues - as title suggests

(in a nut shell)

  1. Register the mappings in the correct order
  2. Set the redirect of the default.aspx
  3. parameter names match

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Routing - my simple test

Published 6/22/2009 by Dave in asp.net
Tags: ,

ASP.NET MVC comes with a routing engine, and from my understanding this will be applied to ASP.Net (I may be wrong on that). however thats not the point of this post. Today I wanted to note down some simple information about the routing engine.

The routing by default is located in the Global.asax

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = ""// Parameter defaults
);

The route name must be unique
the URL can contain params which are denoted by the curly brackets
finally the default values (for this mapping)

Now lets add a Mapping, I want to be able to goto http://Mydomain/pages/aboutus, the pages just signifies that these are the pages for this website, but the last part i want to be the page name (and thus this should be able to be altered, for example, pages/contactus, or pages/someotherpage.)

The steps (If I want to use another controller, PageController.cs)

1. I think i will create the mapping first

routes.MapRoute(
    "Pages",                                //the name
    "Pages/{pageName}",                     //the url, note 1 param
    new {Controller= "Page", action="Index"}//the defaults
);

Ok you will note the URL does not contain the Controller name ("Page" in this instance) and nether the action ("Index"). these are being set by the defaults.

2. Create the controller (PageController.cs), by right clicking on the controller folder and selecting "New Controller"

public class PageController : Controller
{
    //
    // GET: /Page/

    public ActionResult Index(string pageName)
    {
        //some logic here
        return View();
    }

}

now if you add a break point at the point of the Index method, and browse to the http://myDomain/pages/yourpage, you will see the pageName param contains "yourpage". Fantastic!

If i wanted (out of curiosity) how can i just use the Home controller (provided) and just add a method called Page, I could do something like this

routes.MapRoute(
    "Pages",
    "Pages/{pageName}",
    new {Controller= "Home", action="Page"}
);

note all i had to do is change the controller and action on the default object (nice and simple), here is the method i added to the HomeController.cs

public ActionResult Page(string pageName)
{
    ViewData["Message"] = string.Format("you are veiwing the {0} page", pageName);
    return View();
}

this too populated the pageName param, which then allow me to do some logic and maybe find the data for the requested page (wahey)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

In Source control (SC), when you check in your solution, it does not check in any dll's (i think this is default behaviour).  

Well how does this effect you? It may affect how you handle your project external references (any dll built outside the solution, but not stored in the GAC). These dlls are on your computer. When a team member gets the latest verison from SC, inorder to add to the solution. They will need a copy of  these referenced dll's, as the dll's are not saved in SC. 

So what does SC do? depending on your project type SC will add an expected ("relative") path, for where it should be able to find the referenced dlls. Upon a developer opening the solution it will check this location for the dll and import it.

Where is this expected Path kept?

For projects which include a Proj file, it will be located in the proj file (shown a little later) 

For a Website (not Webapp, as that has a proj file) the bin directory will contain a dll.refresh file for each referenced file.

EXAMPLES....

Here is my Simple solution (I have added this to SC already)

I add a reference to an External dll (rsnWrapper, this project is located in the same workspace)

Note, it looks like noramal, but when I check this in, that Dll will not be placed into SC, only the project file will contain a reference of where to find that file. (Note the Hint Path)

<ItemGroup>
    <Reference Include="RsNWrapper, Version=1.0.3037.19379,
                     Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\RsNWrapper\RsNWrapper\bin\Debug\RsNWrapper.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>

For a Web Site project it has a dll.refresh file (shown below), which is a text file, that contains the location.

if you open this in notepad you will see the link

 

Suggestions,

dll's generated from a solution in the same workspace is fine, any developer which can download all the same projects from SC into his\hers workspace will have the same folder structure as you. All he\she will have to do is compile the other project first (rsnWrapper in my exmaple case).

if the dll is from a projet not in SC, then you will have to make sure that you have the dlls shared between people on your team, and that they place the dll;s in the correct location, which will be relitive to the workspace.

 

A good reference:

http://weblog.xanga.com/monsur/437206798/dllrefresh-and-aspnet.html

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Visual Studio Icons

Published 4/23/2008 by Dave in asp.net | dotNet | General

Visual Studio 2005 and 2008 came with icons!!

VS 2008 location
C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033

 VS 2005 location
C:\Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary

 

Hey we got some icons... :D

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Trust Level

Published 1/29/2008 by Dave in asp.net
Tags:

FYI one of the best links to do with trust levels

<http://msdn2.microsoft.com/en-us/library/ms998326.aspx>

 During the setup of this blog (BlogEngine.Net, which is awesome BTW) I ran into a small snag. The hosting comapny could not run this blog with high trust set. So as I was a little rusty on what the difference between High and Medium (which is what this is now running at) I googled away. The above link contains all the details between all the levels.

Also if you are experencing the same problem, delete the line in the config file, this will then resort to medium trust (if that is the max the server will allow), which will mean you can run the blog

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5