Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi all,

I've been working on a blogging engine for my site recently and have hit accross an issue with urls being different on my live site when compared to my development machine.

I'm using a custom url writer to remap SEO friendly urls to the required page.

For example: http//:empirical-design.com/posts/building+a+better+web.aspx

should remap to:

http://www.empirical-design.com/post.aspx?id=19fe4e9c-135d-4570-9cad-a8d5b8c683df

On my development machine this is working as planned. Any postbacks on the page are registered to

http://localhost:53022/post.aspx?id=19fe4e9c-135d-4570-9cad-a8d5b8c683df and the client callbacks are pointing correctly allowing me to preview or add a comment to the site using the ICallbackEventHandler.

On the live server any postbacks occurring are registering to
http://www.empirical-design.com/posts/post.aspx?id=19fe4e9c-135d-4570-9cad-a8d5b8c683df

As you can see it is inserting the extra path "/posts/" into the url.

I've checked the post results in firebug to confirm this.

Local:
POST http://localhost:53022/post.aspx?id=19fe4e9c-135d-4570-9cad-a8d5b8c683df

Live:
POST http://www.empirical-design.com/posts/post.aspx?id=19fe4e9c-135d-4570-9cad-a8d5b8c683df

In my httpModule im using
context.RewritePath((String.Format("{0}post.aspx?id=", VirtualPathUtility.ToAbsolute("~/")) + objPost.Id.ToString() + GetQueryString(context), False)


to rewite the url (VB). I can't for the life of me get this to factor correctly. Does anyone have any ideas?

Many thanks in advance.

Update**************
Thanks Abhishek Sur for your input. I'm using context.RewritePath though which requires a virtual path so I can't use the absolute Url (have I missed something?
Posted
Updated 6-Jan-10 9:20am
v2

Yes I know,

UrlRewrite always bugs me.. If it works correctly in debug env, it create problems in the original server.

So While doing this I always use Safe coding. I recreate the whole path locally and then redirect.

I would have used :
context.Request.Url.Scheme + "://" + context.Request.Host + ":" + context.Request.Port + yourpath<br />
[Note to check this before update]

This would ensure that your application is working in all environment.
:rose:
 
Share this answer
 
Comments
Dalek Dave 22-Oct-10 3:31am    
Good call.
Just found the solution to my problem.

http://weblogs.asp.net/jezell/archive/2004/03/15/90045.aspx[^]

Remarkable stuff and easy to understand too. Thanks for reading my question.
 
Share this answer
 
Thanks so much, I had the same problems with mine. I am going to see if your answer can further solve my issue as well.
 
Share this answer
 
If you use Request.Url then it will return current url on the address bar.
C#
StringBuilder url = new StringBuilder();
url.Append(Request.Url.ToString());
url.Replace("post/", "").ToString();


After this code,you will get updated URL.

If this helped you then please Vote and marked it as answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900