Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding IIS UrlRewrite seems to break debugging on local IIS server

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)

like image 608
citronas Avatar asked Mar 14 '11 17:03

citronas


People also ask

How do I debug locally in IIS?

To start debugging, select IIS Express (<Browser name>) or Local IIS (<Browser name>) in the toolbar, select Start Debugging from the Debug menu, or press F5. The debugger pauses at the breakpoints. If the debugger can't hit the breakpoints, see Troubleshoot debugging.

How do I fix unable to start debugging on web server?

Restart your Application Pool. Check that your Web Application folder has the right permissions. Make sure that you give IIS_IUSRS, IUSR, or the specific user associated with the Application Pool read and execute rights for the Web Application folder. Fix the issue and restart your Application Pool.

How do I enable remote debugging in IIS?

Select Configure remote debugging to configure the firewall and start the remote debugger. When configuration is complete, the Remote Debugger window appears. The remote debugger is now waiting for a connection. Use the server name and port number shown to set the remote connection configuration in Visual Studio.


2 Answers

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.

like image 58
Kirk Woll Avatar answered Sep 26 '22 02:09

Kirk Woll


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).

like image 36
Doug Avatar answered Sep 27 '22 02:09

Doug