472,965 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 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 926
"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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.