and i cant find the RouteConfig class either that is mentioned in the txt document that pops up.
If your app had a RouteConfig class before installing
ASP.NET Friendly URLs package:
----------------------------------------------------------
You'll need to update your RouteConfig class to enable
Friendly URLs.
Call EnableFriendlyUrls() in your RegisterRoutes method:
public static void RegisterRoutes(RouteCollection routes)
{
routes.EnableFriendlyUrls();
}
Can't get it to work, what am i doing wrong? any other examples?
you dont need the .CS, the .ASPX is fine... you just need to use a script section.
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Utils.RegisterRoutes(System.Web.Routing.RouteTable.Routes)
End Sub
.....other stuff....
</script>
As you can see from my example, I use a UTILS class and put all the RegisterRoutes in that class. You will find this easier to keep track of (in my opinion). Here is a sample of my UTILS method:
Public Shared Sub RegisterRoutes(ByVal routes As System.Web.Routing.RouteCollection)
routes.MapPageRoute("News-Routes", "news/{article}", "~/News.aspx", False)
End Sub
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
okay this worked fine with the import namespace but i still dont get where and how the RegisterRoutes class is supposed to be becouse it is still not working and can't find the RegisterRoutes class to enable routing wich i guess is the problem becouse i
can use the route namespace now but i can't use the RouteConfig.RegisterRoutes(RouteTable.Routes); in my application start
you dont need the .CS, the .ASPX is fine... you just need to use a script section.
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Utils.RegisterRoutes(System.Web.Routing.RouteTable.Routes)
End Sub
.....other stuff....
</script>
As you can see from my example, I use a UTILS class and put all the RegisterRoutes in that class. You will find this easier to keep track of (in my opinion). Here is a sample of my UTILS method:
Public Shared Sub RegisterRoutes(ByVal routes As System.Web.Routing.RouteCollection)
routes.MapPageRoute("News-Routes", "news/{article}", "~/News.aspx", False)
End Sub
where is
Public Shared Sub RegisterRoutes(ByVal routes As System.Web.Routing.RouteCollection)
routes.MapPageRoute("News-Routes", "news/{article}", "~/News.aspx", False)
End Sub
supposed to exist? in a class document on it's own? in the Global.asax? i can't find it anywhere
you dont need the .CS, the .ASPX is fine... you just need to use a script section.
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Utils.RegisterRoutes(System.Web.Routing.RouteTable.Routes)
End Sub
.....other stuff....
</script>
As you can see from my example, I use a UTILS class and put all the RegisterRoutes in that class. You will find this easier to keep track of (in my opinion). Here is a sample of my UTILS method:
Public Shared Sub RegisterRoutes(ByVal routes As System.Web.Routing.RouteCollection)
routes.MapPageRoute("News-Routes", "news/{article}", "~/News.aspx", False)
End Sub
i tried like this in my Global.asax
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("About-Routes", "about/", "~/About.aspx", false);
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
and no errors and everything exists , but it doesnt seem to work, when i go into my About.aspx nothing happens
I have only tried this on localhost the normal connection used in visual studio, can that be the problem? i don't have permission yet to turn of the current website to test this , wich is needed becouse the current website is running with 2.0 and i need
4.0 or later for this to work.
can that be the problem? that i have only tried this on local?
I have only tried this on localhost the normal connection used in visual studio, can that be the problem? i don't have permission yet to turn of the current website to test this , wich is needed becouse the current website is running with 2.0 and i need
4.0 or later for this to work.
can that be the problem? that i have only tried this on local?
No, But If you have IIS 6.0, just create a separate application pool for the 4.0 application in IIS.
SKDl
Member
202 Points
208 Posts
help with friendly urls
Jan 09, 2013 01:18 PM|LINK
Hi i have tried a couple of things and are currently trying with this link
http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx
there is a good explanation to how it works and such but i still can't get it to work.
my problem is that i dont have a Global.asax.cs where i should put some code to refer it. I do have a Global.asax
and i have tried with creating a Global.asax.cs but then it can't find the
RouteConfig.RegisterRoutes(RouteTable.Routes);
even tough i added using System.Web.Routing;
wich exists and i installed it like with nugets library package manager with the code provided in the link:
Install-Package Microsoft.AspNet.FriendlyUrls -Pre
and it installs without any conflicts/errors
and i cant find the RouteConfig class either that is mentioned in the txt document that pops up.
If your app had a RouteConfig class before installing
ASP.NET Friendly URLs package:
----------------------------------------------------------
You'll need to update your RouteConfig class to enable
Friendly URLs.
Call EnableFriendlyUrls() in your RegisterRoutes method:
public static void RegisterRoutes(RouteCollection routes)
{
routes.EnableFriendlyUrls();
}
Can't get it to work, what am i doing wrong? any other examples?
Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: help with friendly urls
Jan 09, 2013 01:48 PM|LINK
you dont need the .CS, the .ASPX is fine... you just need to use a script section.
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Utils.RegisterRoutes(System.Web.Routing.RouteTable.Routes)
End Sub
.....other stuff....
</script>
As you can see from my example, I use a UTILS class and put all the RegisterRoutes in that class. You will find this easier to keep track of (in my opinion). Here is a sample of my UTILS method:
Public Shared Sub RegisterRoutes(ByVal routes As System.Web.Routing.RouteCollection)
routes.MapPageRoute("News-Routes", "news/{article}", "~/News.aspx", False)
End Sub
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
Nirav Golani
Member
745 Points
257 Posts
Re: help with friendly urls
Jan 09, 2013 02:01 PM|LINK
Hello SKDI,
On your Global.ascx add following namespace:
You will be able use your methods now.
No need of Global.ascx.cs
Nirav Golani.
SKDl
Member
202 Points
208 Posts
Re: help with friendly urls
Jan 10, 2013 06:38 AM|LINK
okay this worked fine with the import namespace but i still dont get where and how the RegisterRoutes class is supposed to be becouse it is still not working and can't find the RegisterRoutes class to enable routing wich i guess is the problem becouse i can use the route namespace now but i can't use the RouteConfig.RegisterRoutes(RouteTable.Routes); in my application start
SKDl
Member
202 Points
208 Posts
Re: help with friendly urls
Jan 10, 2013 06:39 AM|LINK
where is
Public Shared Sub RegisterRoutes(ByVal routes As System.Web.Routing.RouteCollection)
routes.MapPageRoute("News-Routes", "news/{article}", "~/News.aspx", False)
End Sub
supposed to exist? in a class document on it's own? in the Global.asax? i can't find it anywhere
SKDl
Member
202 Points
208 Posts
Re: help with friendly urls
Jan 10, 2013 09:15 AM|LINK
i tried like this in my Global.asax
<%@ Application Language="C#" %> <%@ Import Namespace="System.Web.Routing" %> <script runat="server"> public static void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("About-Routes", "about/", "~/About.aspx", false); } void Application_Start(object sender, EventArgs e) { // Code that runs on application startup RegisterRoutes(System.Web.Routing.RouteTable.Routes); } void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown } void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs } void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started } void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised only when the sessionstate mode // is set to InProc in the Web.config file. If session mode is set to StateServer // or SQLServer, the event is not raised. } </script>and no errors and everything exists , but it doesnt seem to work, when i go into my About.aspx nothing happens
priyankmtr
Contributor
2626 Points
526 Posts
Re: help with friendly urls
Jan 10, 2013 09:17 AM|LINK
try routes.MapPageRoute("About-Routes", "/about", "~/About.aspx", false); instead of routes.MapPageRoute("About-Routes", "about/", "~/About.aspx", false);(Mark as Answer If you find helpful)
SKDl
Member
202 Points
208 Posts
Re: help with friendly urls
Jan 10, 2013 10:47 AM|LINK
if i do that then i get an error that says:
The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl
SKDl
Member
202 Points
208 Posts
Re: help with friendly urls
Jan 11, 2013 07:42 AM|LINK
I have only tried this on localhost the normal connection used in visual studio, can that be the problem? i don't have permission yet to turn of the current website to test this , wich is needed becouse the current website is running with 2.0 and i need 4.0 or later for this to work.
can that be the problem? that i have only tried this on local?
xmione
Member
344 Points
80 Posts
Re: help with friendly urls
Jan 11, 2013 08:29 AM|LINK
Hi SKDI,
No, But If you have IIS 6.0, just create a separate application pool for the 4.0 application in IIS.
Regards