简体   繁体   中英

IIS URL rewrite not working, the input URL not even captured?

The Failed Request Tracing works fine to log failed rewritings. I can view the log files and at least understand why the rewriting not working.

The regex pattern has passed a matching test OK, but the input URLs I enter in the browser are not even captured. All the URLs mapped to controller actions are captured (my website is an ASP.NET MVC app) however the URL I need to be rewritten is not mapped to any, the page shows 404. But I expect it to be rewritten to some working URL (to test it out, so that instead of showing 404, it should be rewritten to the target url and shows the returned content from there).

My URL rewriting rule uses a Reverse Proxy template.

I hope what I understand here is correct. How can I diagnose this? My purpose is just to do something like turning IIS into a reverse proxy by capturing all requests through my website, check if any matching the defined regex pattern before requesting to the rewritten URL and returning back the content to the original client.

Update

For those who may not know about ASP.NET MVC:

Suppose my website has a controller called HomeController with action Index and the URL mapped to it is /Home/Index .

The URL I mean not mapped to any action here may be /Home/TestProxy Here the HomeController does not expose any action TestProxy and also there is not any routing rule maps /Home/TestProxy to any action. So in this case the ASP.NET MVC app will shows a 404 page.

As I said above, for the URLs mapped to a valid controller action, they seem to be captured and considered as input URLs (before being checked against the rewriting rule). But for URLs not mapped to any controller action (showing 404), I don't see any logged as input URLs (so of course they will not be checked against the rewriting rule and it won't work).

Update 2

Actually my tested URL is not even mapped to a controller so looks like it's not logged by the Failed Requests Tracing rule I setup. Now I've tried using a URL mapped to a controller but not to any action (it still shows 404) but successfully logged by the Failed Request Tracing rule. I can see this in the log file:

<EventData>
   <Data Name="ContextId">{80000034-0000-F000-B63F-84710C7967BB}</Data>
   <Data Name="Pattern">testproxy/(.*)</Data>
   <Data Name="Input">home/testproxy/index</Data>
   <Data Name="Negate">false</Data>
   <Data Name="Matched">true</Data>
</EventData>

So it reported a matched pattern, but still the page shows 404, whereas I expected it to return the content from the rewritten url (which should be http://10.0.0.5/index - I confirm that this URL works if requested directly, it's just another simple published website on local network). I don't even know if this is possible now or I did something wrong here.

URL rewrite inbound rule get executed before controller action.It is appreciated if you could post full error message in your Failed request tracing log.

If the request http://10.0.0.5/index but return 404 from IIS. It sounds like your ARR proxy was not enabled at all. First of all, please try to disable reverse proxy outbound rule. Then go to IIS manager->server node->application request routing cache->Server proxy setting->Enable proxy.

Update:

The rewrite rule has worked and it seems that the request was stopped by

[HttpException]: The controller for path '/questions/62078944/iis-url-rewrite-not-working-the-input-url-not-even-captured' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->"

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