Adding IIS UrlRewrite seems to break debugging on local IIS server

旧城冷巷雨未停 提交于 2019-12-03 09:30:49

问题


This issue is driving me insane: I was working on a recently created project and suddenly I was unable to debug that specific project.

I'm using a local IIS 7.5 with the IIS UrlRewrite 2 module. My development machine is a Windows 7 x64 with Visual Studio 2010 Professional.

Debugging in other projects does still work. I've set an entry in the local IIS and I start debugging my ASP.net 4.0 projects on my local IIS.
I was able to track the debugging issue down to unexpected behaviour with the URL Rewrite 2 module and to reproduce the problem with a freshly created 4.0 Web Application Project:

After adding an simple URL Rewrite rule with the administrative designer in the IIS I'm unable to start debugging, because I receive the error message

Unable to start debugging on the web server. Could not start ASP.Net debugging.  
More information may be available by starting the project without debugging.

(I've also tried copying URL-Rewrite settings from other projects, without success so far)
Starting the project without debugging works perfectly and does not reveal any error!

Other than that, I only added some characters to the default text of the default.aspx

Site settings in the IIS:
- I created a new site, assigned a binding (which port doesn't matter, for instance I tried port 86) just like I always do.
- I set the user identity in the newly created application pool to 'networkservice'
- Set the framework version of the newly created application pool to '4.0'
- I've given the user 'networkservice' full directory permissions to the solution directory

I've also tried several other settings combination, like enabled WindowsAuthentification, FormsAuthentication et cetera. Without luck so far.

This is Web tab of the project:
Servers: Use Local IIS Web Server, Project Url "http://localhost:86/" (I've also tried using "http://localhost:86", does not seem to make a difference)

What is going on here? I'm losing my mind here. Any ideas on how to fix this? (Not using the UrlRewrite 2.0 module is no option)

And finally the web.config:

<?xml version="1.0" encoding="UTF-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true" />
        <rewrite>
            <rules>
                <rule name="LowerCaseRule1" stopProcessing="true">
                    <match url="[A-Z]" ignoreCase="false" />
                    <action type="Redirect" url="{ToLower:{URL}}" />
                </rule>
            </rules>
        </rewrite>
  </system.webServer>
</configuration>

Update: Apparently I can debug with the ActionType="Rewrite" but not with ActionType="Redirect". Still no real option though, because I want that issue fixed in the first placed and not stubling around with some workaround. I'd really like to offer a bounty right now, but the system won't let me.

Can anybody please reproduce my steps? (I got this on 2 different computers so far)


回答1:


Visual Studio, when starting up, will (for some reason) attempt to access the URL:

/debugattach.aspx

If you have a rewrite rule that redirects (or otherwise catches), say, .aspx files, somewhere else then you will get this error. The solution is to add this section to the beginning of your web.config's <system.webServer>/<rewrite>/<rules> section:

<rule name="Ignore Default.aspx" enabled="true" stopProcessing="true">
    <match url="^debugattach\.aspx" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="None" />
</rule>

This will make sure to catch this one particular request, do nothing, and, most importantly, stop execution so none of your other rules will get run. This is a robust solution, so feel free to keep this in your config file for production.




回答2:


I just discovered that the if the project URL you are using (right click your project, go to Properties, click on the Web tab on the left) happens to trigger your rewrite rule, then debugging using the play button won't work. The "fix" is to simply set your project URL to one that won't be rewritten.

For example, I am using URL rewrite to make sure that HTTP requests get redirected to HTTPS. As long as my project URL begins with https:// then I have no issues debugging (apart from the fact that I have to install an SSL cert on my development machine, but that's easy to work around).




回答3:


The problem is that all files will be forced to use a rule, unless they are explicitly excluded by a condition. I don't have the source code anywhere near me, but I guess this made the trick:

  <conditions>
    <add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
  </conditions>

The LowerCaseRule entry should look like this:

<rule name="LowerCaseRule1" enabled="true" stopProcessing="true">
  <match url="[A-Z]" ignoreCase="false"/>
  <conditions>
    <add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
  </conditions>
  <action type="Redirect" url="{ToLower:{URL}}"/>
</rule> 



回答4:


I was having the same problem. I couldn't start my project to debug in visual studio. I followed more than one instruction you guys gave.

First of all I had to create a rule to ignore the page /debugattach.aspx, just as @Kirk Woll said.

Second, I had to follow the Doug instruction. My project was pointed to start action through the page "index.aspx", and my rule is created to remove the aspx extension. So, changing the start page to the page already formatted (with no .aspx) it worked perfectly.

Ps. 1: I have more than 5 rules in my project, I've isolated one by one to identify which rule was causing the problem, and I figured out that the rule that was causing the problem was the rule that removes the aspx extension.

Ps. 2: Even correcting the project start page, it still not working, it only worked when I added the rule that ignores the page /debugattach.aspx.

Ps. 3: I hadn't to change any of my rules to match some pattern that I should ignore




回答5:


I had a similar problem using VS 2010, IIS 7, and URLRewriter 2 and found a workaround - though hopefully someone will post a real solution for you.

You can attach the debugger to the IIS process and debug as follows: 1. In Visual Studio, click Debug > Start without debugging 2. Set a breakpoint 3. Click Debug > Attach to Process.
3. Check the "Show processes in all sessions" checkbox. 4. Highlight w3wp.exe (the iis worker process) and click "Attach" 5. In your browser, go to the url that will cause your breakpoint to be hit 6. In Visual Studio, the code should be paused at your breakpoint and you can step through as usual.




回答6:


I was having this issue and the solution was to add the host name to the site bindings in IIS and then change the project URL from http to https.



来源:https://stackoverflow.com/questions/5302317/adding-iis-urlrewrite-seems-to-break-debugging-on-local-iis-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!