Solved

MVC Rewrite URL Through Router in ASP.NET

Posted on 2011-03-06
10
862 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now