IIS Rewrite Problem

John Reynolds 0 Reputation points
2024-01-21T03:51:28.5366667+00:00

I am having a problem with IIS Rewrite.

This is on a website upgraded from asp.net 4.XX to .NET 8. The old code displayed images via a handler and the database has many entries that show an image via:

/showimage.ashx?id=53810&t=2

Those images will, of course, not display in .NET 8 code via the handler

So, in .NET 8, I wrote a rewrite rule as follows:

^/ShowImage.ashx?id=([0-9]+)&t=([_0-9a-z-]+)$

it should rewrite to /images/RetrieveImage/{R:1}/{R:2}

which is a working MVC route to display images in the .NET 8 code

and it tests ok in IIS Rewrite to return the R:1 and R:2 values.

However, the rewrite to display the image fails to rewrite and display the images on .NET 8 code web pages that include an image originally displayed from the database as

/showimage.ashx?id=53810&t=2

Windows development Internet Information Services
Developer technologies .NET Other
{count} votes

2 answers

Sort by: Most helpful
  1. John Reynolds 0 Reputation points
    2024-01-22T18:19:37.2966667+00:00

    The rewrite rule from web.config is:

    			<rule name="showimage.ashx" stopProcessing="true">
    					<match url="^/ShowImage\.ashx\?t=(\d+)&amp;id=(\d+)$" />
    					<conditions>
    									
    					</conditions>
    					<action type="Rewrite" url="/images/RetrieveImage/{R:2}/{R:1}" appendQueryString="false" />
    				</rule>
    
    

    showimage.ashx does not exist on the .NET 8 site, but text retrieved from sql for display in web pages does contain links to that file from the asp.net 4 code. The rule tests ok in IIS Rewrite program, for example, for input of : /showimage.ashx?id=53810&t=2 Could the failure when running on server be due to ISAPI or CGI restrictions on the server?

    0 comments No comments

  2. John Reynolds 0 Reputation points
    2024-01-22T18:59:10.3966667+00:00

    Correction - the rule tests ok against --- /showimage.ashx?t=2&id=52114 but does not display the rewritten mvc route image of url="/images/RetrieveImage/{R:2}/{R:1}" I know the url above will work as it does if I use the actual digits as follows: src="/images/RetrieveImage/52114/2"


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.