简体   繁体   中英

Rewrite map url to address in root folder IIS 10 on Windows Server 2016

I have an MVC application and I'm trying to do some basic url rewriting using rewrite maps in IIS 10 on windows server 2016. I've mapped the.htm extension to the System.Web.UI.PageHandlerFactory so i can view dynamic pages on seemingly static urls.

This rule works:

 <add key="/folder/product.htm" value="/Products/Details?ID=1" />

this rule does not:

 <add key="/product.htm" value="/Products/Details?ID=1" />
and worse, this one throws an IIS error,

System.Web.HttpException: Cannot use a leading.. to exit above the top directory.

Removing the leading slash doesn't work either, it results in a 404 error.

What is the correct way to rewrite a url to the root directory of the site? Thanks.

If you want /folder/product.htm and /product.htm to jump to /Products/Details?ID=1, you can try the following URL Rewrite Rule:

    <rules>
        <rule name="Test">
            <match url="(product.htm)" />
            <action type="Rewrite" url="/Products/Details?ID=1" />
        </rule>
    </rules>

For free let me know if you have any other questions.

This was a route configuration issue. I solved it by adding this to my route config file:

 routes.MapRoute( name:="Product", url:="product", defaults:=new with{.controller = "Products", .action= "Details", .id=1 } )

then i changed the rewrite map to respond to the route.

 <add key="/product.htm" value="/product" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM