Solved

MVC Rewrite URL Through Router in ASP.NET

Posted on 2011-03-06
10
873 Views
Last Modified: 2012-05-11
1) routes.Add("Articles", New Route("{product_name}/{c_id}/{sc_id}", New WebFormRouteHandler("~/products.aspx")))

We get url of about path

http://www.sitename.com/Articles/1/17

But problem is that When i m on this page then we move out on the another page
so my url is

http://www.sitename.com/Articles/1/aboutus

but Actual it should be

http://www.sitename.com/aboutus

Looking forward for response.
0
Comment
Question by:citadelind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:robasta
ID: 35053426
its probably because the link to About us  on the Articles page is something like this:

<a href="aboutus">xxx</a>


this is relative to the current url and assumes that the page is at the same directory level. What you need to do is add a trailing slash that will say the page/path is at the root i.e.

<a href="/aboutus">xxx</a>

If you are using the helper methods to generate the links, you need to include the controller (e.g. Home)
0
 

Author Comment

by:citadelind
ID: 35053750
It is not working. Please give me proper solution which i given to you.

It is same problem. Please give me example how can i do?
0
 
LVL 14

Expert Comment

by:robasta
ID: 35053877
post the html
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:citadelind
ID: 35054051
I am attaching my global.aspx as txt format file so please check it.

and i also set url of

<a href="Productname/1/17">xxx</a> Global.txt
0
 
LVL 14

Expert Comment

by:robasta
ID: 35054163
post the link to 'aboutus'. i dont think its the routing thats causing the problem. How are you linking from this page: http://www.sitename.com/Articles/1/17 to AboutUs?
0
 

Author Comment

by:citadelind
ID: 35054195
Ya when i write
http://www.sitename.com/Articles/1/17 to AboutUs

Then it is working but Now problem is that
when i m on this page
http://www.sitename.com/Articles/1/17 

Then now i used another link like (contact us) on this page then url comes

http://www.sitename.com/Articles/1/contactus

So it is wrong,
When i m on the page then i used contact us link then it should open

http://www.sitename.com/contactus

This format.
I hope you are getting me.
0
 
LVL 14

Accepted Solution

by:
robasta earned 500 total points
ID: 35054276
i get you.

here is how html links work:

if you are on page http://www.sitename.com/Articles/1/17 , and on that page, you need to link to http://www.sitename.com/aboutus , then the <a href=""> link should be:

Absolute Link:<a href="http://www.sitename.com/aboutus">

 or

Relative to the site <a href="/aboutus">

If (and im guessing thats how your links are currently working) you have <a href="aboutus">, this is relative to the current directory.

This is how Html links work, it should not have anything to do with the routes you specified. Are you using a master page? if so, post it here.
0
 

Author Comment

by:citadelind
ID: 35054375
Thanks i got solutions about this issue.
Thank you.

But one problem facing

When i m on the page
http://www.sitename.com/Articles/1/17 

All images are gone, bz my directory is images/logo.jpg on the root folder.
so when i am using about link then all images and css are gone.

Please give me solution how can i access all the images and css this page.

0
 

Author Comment

by:citadelind
ID: 35054432
you can ans me image issue on this new question i posted

http://www.experts-exchange.com/Programming/Languages/.NET/Q_26867559.html
0
 

Author Closing Comment

by:citadelind
ID: 35056420
good work
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question