Solved

MVC Rewrite URL Through Router in ASP.NET

Posted on 2011-03-06
10
871 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create an MVC5, Razor Widget 2 36
SSIS On fail action 5 48
Input parameteres to DragOver 2 34
custom authorization on controller action and HTML in asp.net mvc 1 42
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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