473,414 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Plese help with my codes

Hi,

This is te first time I use url rewriting. What I am trying to accomplish:
Hide the .aspx extension and give user a shorter path to type, say the user
can type "/sales" in browser and the browser will display
"/topic.aspx?topic=sales"

To do this, I created a "sales" folder and put a dummy "default.aspx" in it,
then I tried the following codes:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Request.Path.ToLowerInvariant().IndexOf("sales/default.aspx")
!= -1)
HttpContext.Current.RewritePath("/topic.aspx?topic=sales");
if (Request.Path.ToLowerInvariant().IndexOf("support/default.aspx")
!= -1)
HttpContext.Current.RewritePath("/topic.aspx?topic=support");

the browser displays the correct html, but all the images become broken and
all links are linked to "sales" folder instead of application root. I know I
did it wrong, just don't know how to correct it.

TIA
Jun 27 '08 #1
1 941
"Raymon Du" <rd**@yahoo.comwrote in message
news:uo**************@TK2MSFTNGP06.phx.gbl...
This is te first time I use url rewriting. What I am trying to accomplish:
Hide the .aspx extension and give user a shorter path to type, say the
user can type "/sales" in browser and the browser will display
"/topic.aspx?topic=sales"

To do this, I created a "sales" folder and put a dummy "default.aspx" in
it, then I tried the following codes:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Request.Path.ToLowerInvariant().IndexOf("sales/default.aspx")
!= -1)
HttpContext.Current.RewritePath("/topic.aspx?topic=sales");
if (Request.Path.ToLowerInvariant().IndexOf("support/default.aspx")
!= -1)
HttpContext.Current.RewritePath("/topic.aspx?topic=support");

the browser displays the correct html, but all the images become broken
and all links are linked to "sales" folder instead of application root. I
know I did it wrong, just don't know how to correct it.
When your HTML page contains an <img src='whatever'>, it is the browser
the one that "builds" the URL of the image and requests it from the server.
If you are using is a relative path, the browser will append it to whatever
it thinks is the current page and then request that from the server. If you
are using URL rewriting, the path that the browser "sees" is different from
the real path of the page, so it is sending to the server a request that
doesn't match the path that you intended for that image.
The easiest remedy is to use absolute urls for your images instead of
relative urls, or to move the images into a path that matches your rewritten
urls. A more sophisticated approach would use a different extension for the
images (for instance, .ashx instead of .jpg) so that they are routed into
aspnet rather than being served directly by IIS, and then performing url
rewriting also for the images and not only for the pages.

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yong Wang | last post by:
Hi, All: We have a network management system written in C++, MysQL, and Hp SNMP. It works in Solaris command line. When I wrote a similar python codes which call compiled C++ and mysql codes in...
29
by: Maurice LING | last post by:
Hi, I remembered reading a MSc thesis about compiling Perl to Java bytecodes (as in java class files). At least, it seems that someone had compiled scheme to java class files quite successfully....
3
by: aman | last post by:
i know how to get scan codes and ascii codes for special keys. i can get ascii codes of alphabetic keys. how does one get scan codes of alphabetic keys??
3
by: c# beginner | last post by:
we are trying to standardize return codes across our .NET applications (that are soon to be developed.) What is the best practice for standardizing return codes? I know of only the following...
1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
4
by: mainargv | last post by:
hi How do you rewrite codes with " ... va_list va_start va_etc", so that simple c compiler don't have to deal with them. I have written a simple c->verilog compiler but it can't deal with...
3
by: PerlPhi | last post by:
hi! i have a Perl code in here that when ran the program accepts any Perl codes from the user input (<STDIN>, of course use no syntax errors), then after breaking the multiline input, the inputs will...
9
viswammamilla
by: viswammamilla | last post by:
Hai to everyone.I need a help I have an application,in this user want to type his IP address.I want MaskedtextBox for IP address format like 192.168.0.10 like this,in my toolbox i didnt have...
1
by: rob41 | last post by:
This is the code and I'm getting a syntax error at the From statement: Msg 156, Level 15, State 1, Line 33 Incorrect syntax near the keyword 'FROM'. Any suggestions on what've done wrong? ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.