473,396 Members | 1,789 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,396 software developers and data experts.

URLs, 404 redirect etc.

Hi all,

Using C#.NET 1.1

I am progressing on my URL ReWriting quite well, but have a slight problem.

My server will not have real paths, just virtual, which is generated from a
database. This will include images, documents etc. (The images will map (URL
ReWrite) to real images of a different name.)

I am using the IIS 404 error to redirect to an ASPX page, which will then
allow my system to handle everything that does not exist on the file system.
This is working fantastically, though I do have a slight niggle with it.

If I call a virtual image (i.e. I don't have the real file, but I will URL
ReWrite to the correct image), my 404 handler gets called (this is what I
expect). As the handler is .ASPX, my URL ReWrite code in global.asax.cs gets
called. (Again, this is what I expect). I then rewrite the call to the image
to the real image that will be displayed. (This again is working like a
dream). However, what I didn't expect is the 404 handler page (even though
it doesn't actually get hit) is recorded in the web log files as the
requested item.

Trying to resolve this, I have passed the URL Rewriter to call the 404 page
direct and pass a parameter in the querystring. In my 404 page, I do a
response.redirect to the image that I want. This sort of works, but I get
the 404 page with a 304 response AND the rewritten image recorded in the log
files. I can live with the rewritten image (not the called image name) but I
don't want the 404 page to show up in my logs.

So, I tried a server.transfer inside the 404 page. This shows the image, but
it records the 404 page in the logs.

I am looking for ideas as to how to get around this problem.

In summary...
If I call an image (which needs to be URL ReWritten), I want the image to be
recorded in the log. This works fine if I call aspx pages (though not yet
tried it for classic asp, but really, I am not so interested in that at the
moment).

Any ideas?

BTW. I cannot do anything that will need to be installed on a server. This
has to be copy and paste deployment (i.e. can be run on a shared server at
an ISP.), so has to be handled within .NET.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Feb 14 '07 #1
5 5981
On Feb 14, 11:20 pm, "David"
<david.colliver.N...@revilloc.REMOVETHIS.comwrot e:
>
I am looking for ideas as to how to get around this problem.
Of course, it does 404 entry in the log because IIS doing it before
your see the page.

You should forget about old 404-style-redirects in .Net, use
HttpModule instead.

Example:

using System;
using System.Web;

namespace SomeModule
{
public class MyModule: IHttpModule
{
#region IHttpModule Members
public void Init(HttpApplication context)
{
context.BeginRequest += new
EventHandler(context_BeginRequest);
}

public void Dispose() { }
#endregion

private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
if (app.Context.Request.Url.ToString() == "....old.jpg)
app.Context.RewritePath("new.jpg");

}
}
}
-- in the web.config ---

<httpModules>
<add name="MyModule" type="SomeModule.MyModule, SomeModule" /
>
</httpModules>

After that all requests to old.jpg will be rewrited to new location
and you will have Status 200 in your IIS log.

Feb 14 '07 #2
Hi,

Thanks for this...

The old style 404 redirect does work if I call an unknown page, but for some
reason, not my images. My page name gets logged in the log files.

The one that you are showing here... how does that hook into the IIS
application? (I do not know the answer to this, so this is a genuine
question) How can .NET trap for unknown files?

What I also need to do (which currently does work) is to be able to rewrite
files with no extension (for example, a directory). Will this HttpModule work
for that?

Thanks.

Regards,
Dave Colliver.
http://www.LiverpoolFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Alexey Smirnov" wrote:
On Feb 14, 11:20 pm, "David"
<david.colliver.N...@revilloc.REMOVETHIS.comwrot e:

I am looking for ideas as to how to get around this problem.

Of course, it does 404 entry in the log because IIS doing it before
your see the page.

You should forget about old 404-style-redirects in .Net, use
HttpModule instead.

Example:

using System;
using System.Web;

namespace SomeModule
{
public class MyModule: IHttpModule
{
#region IHttpModule Members
public void Init(HttpApplication context)
{
context.BeginRequest += new
EventHandler(context_BeginRequest);
}

public void Dispose() { }
#endregion

private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
if (app.Context.Request.Url.ToString() == "....old.jpg)
app.Context.RewritePath("new.jpg");

}
}
}
-- in the web.config ---

<httpModules>
<add name="MyModule" type="SomeModule.MyModule, SomeModule" /
</httpModules>

After that all requests to old.jpg will be rewrited to new location
and you will have Status 200 in your IIS log.

Feb 15 '07 #3
On Feb 15, 10:25 am, David Colliver
<DavidColli...@discussions.microsoft.comwrote:

David, I'm sorry, I forgot that for images (and files with no
extension) you have to register the extension within IIS (what you
don't want to do).

There are many articles about custom httpmodules and httphandlers
(where you can handle the requests based on the type of file extension
used)

You should check this one
http://msdn2.microsoft.com/en-us/library/ms972974.aspx

But using httpmodules and httphandlers for the other files (not
*.aspx, or similar) required to register the extension within IIS and
ASP.NET

Feb 15 '07 #4
On Feb 15, 10:25 am, David Colliver
<DavidColli...@discussions.microsoft.comwrote:
What I also need to do (which currently does work) is to be able to rewrite
files with no extension (for example, a directory). Will this HttpModule work
for that?
P.S.

For links such as http://site/Dir/Dir/Dir/PageDoesNotExist.aspx this
HttpModule will work.

If you don't want to change anything in IIS, this HttpModule will work
for files with no extension if you created a directory with the same
name and empty default.aspx in it.

For example, to rewrite URL http://site/PageDoesNotExist to another
page you need to create a directory named PageDoesNotExist and put a
file default.aspx into this directory.

Feb 15 '07 #5
Hi,

Thank you.

I am not currently using httpmodule, but have my current re-write code
inside my application_beginrequest of global.asa.

I am aware of the issues of having no real pages or folders, which is why I
am handling through the IIS 404 handler. What I didn't know is if you knew
something I didn't, to which I continued my question.

The app I am building has to be done in a virtual way (i.e. virtual files
and folders rather than real files and folders). The current IIS way of
handling it works brilliantly apart from the log file. :-(

If anyone has any ideas of getting the correct file listed in the log file
instead of my redirect handler, I would very much appreciate it.

Thanks.

Regards,
Dave Colliver.
http://www.SheffieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Alexey Smirnov" wrote:
On Feb 15, 10:25 am, David Colliver
<DavidColli...@discussions.microsoft.comwrote:
What I also need to do (which currently does work) is to be able to rewrite
files with no extension (for example, a directory). Will this HttpModule work
for that?

P.S.

For links such as http://site/Dir/Dir/Dir/PageDoesNotExist.aspx this
HttpModule will work.

If you don't want to change anything in IIS, this HttpModule will work
for files with no extension if you created a directory with the same
name and empty default.aspx in it.

For example, to rewrite URL http://site/PageDoesNotExist to another
page you need to create a directory named PageDoesNotExist and put a
file default.aspx into this directory.

Feb 15 '07 #6

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

Similar topics

10
by: Chris Guimbellot | last post by:
Hello, I am trying to create vanity URLs (I think that's what they are called) that link directly to an item's listing page on my site. Currently, the urls are set up something like the...
1
by: Mike P | last post by:
I'm using MamboServer for my site, and have switched from SEF URLs to standard URLs. Of course, I'm indexed everywhere with the SEF urls. I'm trying to write a script, so that users and search...
8
by: msnews.microsoft.com | last post by:
I want to redirect the user to a url outside of our website but I want it to preserve our application's window by opening a new window. We have a datagrid that has five hyperlink columns containing...
6
by: Keith Patrick | last post by:
I have to do some programmatic redirects (in several pages) based on URLs I am given from an external source. The URLs have querystrings at the end, but one in particular is about 240 chars long,...
21
by: John | last post by:
Hi, I updated a site and changed the file extensions from .html to .php. Now i noticed that the google does find the old .html pages but since they're not there anymore... they can't be found....
3
by: Polaris431 | last post by:
In code, you can type the following: this.Response.Redirect("~/index.aspx"); Is there anything in ASP.NET that you can use in place of strings when referring to URLs? It would be nice to refer...
2
by: ITistic | last post by:
I am about to start on a migration from a static HTML site to an ASP.NET solution. I've done a ton of these in the past as my primary job duty is developing ASP.NET sites. This is the first project...
0
by: peanutgnome | last post by:
Folks, looking for a little guidance on an .htaccess redirect problem - I'm a bit of a newbie when it comes to the rewriting of urls... We've changed from one CMS to another on our company...
3
by: WebCM | last post by:
How to apply nice URL-s into CMS? 1. Should we use nice urls for every page? 2. Do we need to put a FULL path into <a href="">? 3. What is faster and better? a) 10 rules in .htaccess...
4
by: Guy Macon | last post by:
As a personal learning experience with limited practical use, I have been doing some experiments with using .htaccess to redirect mis-typed URLs to a preferred canonical form. I have set up a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.