URL Rewrite issues on IIS 7.0 with subdomains, not

2019-09-04 18:39发布

问题:

i'm building this asp.net application that require couple of subdomains. they will all share the same code base but i have separate .aspx for each subdomain in its own subfolder, as follows:

admin.domain.com -> domain.com/admin
user.domain.com -> domain.com/user
...

everything works great on my dev box (win7, iis 7.5) using the following rewrite rules:

<rule name="admin.domain.com" stopProcessing="true">
   <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^admin.domain.com$" />
        <add input="{PATH_INFO}" pattern="^/images/" negate="true" />
        <add input="{PATH_INFO}" pattern="^/handlers/" negate="true" />
        <add input="{PATH_INFO}" pattern="^/aspnet_client/" negate="true" />
        <add input="{PATH_INFO}" pattern="^/webservices/" negate="true" />
        <add input="{URL}" pattern="\.axd$" negate="true" />
      </conditions>
      <action type="Rewrite" url="\admin\{R:0}" />
</rule>

When i push my release over to production, which runs Win 2008 R1, on IIS 7.0 the rewrites break. I see that my <form> tag in source of the page points to action="admin/", whereas on 7.5 it points to root. So when i post my forms i get 404s, as there is no /admin subfolder per rewrites.

Is there anything i can do to remedy this? I would like to omit upgrading to R2 just to fix this. Can i upgrade URL Rewrite module alone? Can i fix this using different rewrite rule?

Any help is appreciated!

回答1:

i found a solution, for some reason on iis 7.0 you must add the following where you have your form defined. in my case it was a Page_Load within my master page. hope this helps.

form1.Action = Request.RawUrl