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
Solved

MVC Rewrite URL Through Router in ASP.NET

Posted on 2011-03-06
10
869 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 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