IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
Can anyone help me! I use an application which uses Ajax enabled WCF service including IIS URL rewrite module 2.0. The WCF service seems to be not working when the application is deployed on IIS 7 on windows server 2008 R2 Enterprise edition with SP1 FRENCH machine. While debugging, the path http://localhost/WCFService.svc/jsdebug is redirected to the default.aspx page. This application works fine on a Windows Server 2008 R2 Enterprise edition with SP1 English machine but I am not able to find out the reason why the URL for the web service is redirected to the default.aspx page. I tried all the possible ways I could but it did not helped.
Re: IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
Your problem seems to be unique. Actually the reason according to me is that you cannot create the URL rewrite on the root directory. For that you must have a directory between in order, so that Ajax can continue working. I am sure it will work for sure. If you use master pages then the links on the master pages won’t work on the pages that are in the subfolder where the URL rewriting is on. There might be a possibility of you needing two master pages i.e. one for first level and the other for second level.
Re: IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
Even I am having problems related to it. I am using the below rules and for the URL rewriting I enabled the Failed request tracing, but the logs were empty.These rules are troubleshooting with Windows Server 2008 R2 French version only and on English version it is working fine:
Code:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Default\.aspx$" /> <conditions> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^P=([^=&]+)&L=([^=&]+)$" /> </conditions> <action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" negate="true" pattern="\.axd$">
</conditions>
<action type="Rewrite" url="Default.aspx?P={R:1}&L={R:2}" />
</rule>
Re: IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
According to me the rules should be of the pattern "^([^/]+)/([^/]+)/?$". This will pass evaluation for the request "WCFService.svc/jsdebug". Also add a condition to negate svc requests in your rule, the rules should look like the:
Code:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Default\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^P=([^=&]+)&L=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="\.axd$" negate="true" />
<add input="{URL}" pattern="\.svc" negate="true" />
</conditions>
<action type="Rewrite" url="Default.aspx?P={R:1}&L={R:2}" />
</rule>
Re: IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
Still the application having the URL rewrite problem then you have to do some changes as I recommend. Just move the hosting services. Don’t move it to winhost, try some other hosting service. After doing this, your URL rewrite will work perfectly. The URL will look like http://www.mysite.com/band.aspx?band=u2 and it will be written to http://www.mysite.com/u2 . Put the following code in the webconfig file:
Code:
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<!-- The following condition prevents rule from rewriting requests to .axd files -->
<add input="{URL}" negate="true" pattern="\.axd$" />
</conditions>
<action type="Rewrite" url="band.aspx?band={R:1}" /></rule>
</rules> </rewrite>
Re: IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
If the AJAX fails to load when site placed in the subfolder then you have to place the site within the subfolder using the below rewriting rule in a web.config file at the root level:
Code:
<rule name="Rewrite to folder1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mydomain.org$" />
</conditions>
<action type="Rewrite" url="mysubfolder/{R:1}" />
</rule>
The generated code in default.aspx produces:
Code:
<script src="/mysubfolder/ScriptResource.axd?d=JqgWhplkVbNDB-O-
ThhHizUoDTYJEM-feibV4yvf46HwrI2N5TzSy72-olJ4bTMQzD63KWlitLqI2oLdioZV-Q2&
t=ffffffff966badba" type="text/javascript">
</script>
But the generated code needs to produce:
Code:
<script src="/ScriptResource.axd?d=JqgWhplkVbNDB-O-
ThhHizUoDTYJEM-feibV4yvf46HwrI2N5TzSy72-olJ4bTMQzD63KWlitLqI2oLdioZV-Q2&
t=ffffffff966badba" type="text/javascript">
</script>
Re: IIS Module 2.0 of URL rewrite troubleshooting with Ajax enabled WCF service
To solve this rewrite problem once and for all then you have to perform certain steps as I recommend. After performing can have several asp.net web sites, using Ajax in one hosting account. First create a new subfolder for example “mysubfolder” then upload your new website into it. After that define the folder as an Application Starting point for example “mydomainname.com”. Create a web.config file directly in your root. After that add the following information to your web.config file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="mydomainname.com" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?mydomainname.com" />
<add input="{PATH_INFO}" pattern="^/mysubfolder/" negate="true" />
</conditions>
<action type="Rewrite" url="\mysubfolder\{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>