public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{menu}/{navmenu}/{submenu}", // URL with parameters
new { controller = "jd", action = "Index",menu=UrlParameter.Optional,submenu=UrlParameter.Optional,navmenu=UrlParameter.Optional } // Parameter defaults
);
}
i've only one controller and action to be requested by user. so i wanted to use URL's for taking the input from the user in three optional parameters. they can type anything they want in that URL.
It's working great. for any string like i expected like "www.localhost:3223/one/two/three " forexample. and that url takes me to 'jd' controller, 'index' action. any given url will now take me to the same controller and action.
but this url is not downloading css file : "www.localhost:2343/one/two/three/".
the only difference between these two files, is "/" character after the URL. so this url is taking me to jd controller and index action like we wanted but the page is showing up without css.
What does it look like in the source file on the server? I'm going to guess it's exactly the same -- you need to make the path render dynamically via (assuming Razor):
Yep, so you need to change those src and href paths (for both script and CSS and same would also go for images) to use @Url.Content like I suggested -- this way the client-side path is emitted relative to the URL being requested.
sean freeman
Member
170 Points
96 Posts
Problem with routing.
Apr 28, 2012 06:42 PM|LINK
Hi,
i changed my rounting as follows.
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{menu}/{navmenu}/{submenu}", // URL with parameters new { controller = "jd", action = "Index",menu=UrlParameter.Optional,submenu=UrlParameter.Optional,navmenu=UrlParameter.Optional } // Parameter defaults ); }i've only one controller and action to be requested by user. so i wanted to use URL's for taking the input from the user in three optional parameters. they can type anything they want in that URL.
It's working great. for any string like i expected like "www.localhost:3223/one/two/three " forexample. and that url takes me to 'jd' controller, 'index' action. any given url will now take me to the same controller and action.
but this url is not downloading css file : "www.localhost:2343/one/two/three/".
the only difference between these two files, is "/" character after the URL. so this url is taking me to jd controller and index action like we wanted but the page is showing up without css.
Does anyone know what the problem is?
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Problem with routing.
Apr 28, 2012 06:51 PM|LINK
How are you including the CSS? What does your <link> tag look like?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
sean freeman
Member
170 Points
96 Posts
Re: Problem with routing.
Apr 28, 2012 06:53 PM|LINK
This is the link to css file on disk from rendered page.
<link href="../../Content/mycss.css" rel="stylesheet" type="text/css" />
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Problem with routing.
Apr 28, 2012 06:55 PM|LINK
What does it look like in the source file on the server? I'm going to guess it's exactly the same -- you need to make the path render dynamically via (assuming Razor):
<link href="@Url.Content(~/Content/mycss.css")" rel="stylesheet" type="text/css" />
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
sean freeman
Member
170 Points
96 Posts
Re: Problem with routing.
Apr 28, 2012 06:58 PM|LINK
<!DOCTYPE html > <html> <head> <link href="../../Content/mycss.css" rel="stylesheet" type="text/css" /> <script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script> </head> <body> @RenderBody() <script src="../../Content/JScript1.js" type="text/javascript"></script> </body> </html>no this is looking same even in server code. this is the whole layout page.
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Problem with routing.
Apr 28, 2012 07:11 PM|LINK
Yep, so you need to change those src and href paths (for both script and CSS and same would also go for images) to use @Url.Content like I suggested -- this way the client-side path is emitted relative to the URL being requested.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
sean freeman
Member
170 Points
96 Posts
Re: Problem with routing.
Apr 28, 2012 07:22 PM|LINK
hi,
can you repost that code please?
coz this code is not working: giving a compile error: invalid expression term "/";
<link href="@Url.Content(~/Content/mycss.css")";
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Problem with routing.
Apr 28, 2012 07:24 PM|LINK
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/Code.js")"></script>
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
sean freeman
Member
170 Points
96 Posts
Re: Problem with routing.
Apr 28, 2012 07:25 PM|LINK
Thanks i modified it to
<link href = @Url.Content('~/content/mycss.css')/>
and it's working fine.
thanks
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Problem with routing.
Apr 28, 2012 07:26 PM|LINK
BTW, here's an example from the tutorials (scroll 75% of the way down);
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/