2

I am running a small intranet site off Windows 7 and IIS and I have a page page/LoadPage.aspx which is an ASPX container page for displaying a requested page, e.g. http://localhost/page/LoadPage.aspx?p=downloads (which loads downloads.html located in the root directory).

The problem is, when creating a User-Friendly URL using the URL Rewrite plugin in IIS 7, if the query tag (p) requests a page in a particular directory (e.g. http://localhost/page/LoadPage.aspx?p=downloads/software, which should load the page downloads/software.html) then a 404 error will be thrown because the server thinks the user has requested a directory.

The mapping and redirecting do work for single requests like page/LoadPage.aspx?p=downloads which successfully redirects to http://localhost/downloads.html.

Thank you.

UPDATE: Here is the code. Could it be the problem?

Example URL: /page/LoadPage.aspx?p=downloads (This works and redirects to downloads.html)

Example URL: /page/LoadPage.aspx?p=downloads/software (This doesn't work, but is meant to redirect to /downloads/software.html)

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim p = Request.QueryString("p").ToString
        Dim page = HttpUtility.UrlDecode(p)
        Dim ReadHTML As New IO.StreamReader("\\PC\User\Documents\IIS Websites\Intranet\" & page & ".html")
        container.InnerHtml = ReadHTML.ReadToEnd
    End Sub
2

/ is a reserved character, so you will need to url encode the querystring value.

Your URL should look like this:

http://localhost/page/LoadPage.aspx?p=downloads%2Fsoftware

To use the value in your .NET code, you will need to decode the value:

HttpUtility.UrlDecode(value);

https://msdn.microsoft.com/en-us/library/adwtk1fy.aspx

| improve this answer | |
2

I solved the problem. It seems that IIS does not like / in a query unless it is double escaped like this %252f. However, it will not replace it with a slash and so the URL ends up looking messy. I avoided this problem by using an underscore for my slash symbol: /page/LoadPage.aspx?downloads_software It then replaces the colon with a slash during runtime (the change is not visible in the URL, unfortunately).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.