简体   繁体   English

添加IIS UrlRewrite似乎打破了本地IIS服务器上的调试

[英]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. 我正在使用IIS UrlRewrite 2模块的本地IIS 7.5。 My development machine is a Windows 7 x64 with Visual Studio 2010 Professional. 我的开发机器是带有Visual Studio 2010 Professional的Windows 7 x64。

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. 我在本地IIS中设置了一个条目,我开始在我的本地IIS上调试我的ASP.net 4.0项目。
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 : 我能够使用URL Rewrite 2模块跟踪调试问题,直到出现意外行为,并使用新创建的4.0 Web应用程序项目重现问题:

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 在IIS中添加一个简单的URL重写规则与管理设计器后,我无法开始调试,因为我收到错误消息

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) (我也试过从其他项目复制URL-Rewrite设置,到目前为止没有成功)
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 除此之外,我只在default.aspx的默认文本中添加了一些字符

Site settings in the IIS : 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. - 我创建了一个新站点,分配了一个绑定(哪个端口无关紧要,例如我尝试了端口86),就像我一直这样。
- I set the user identity in the newly created application pool to 'networkservice' - 我将新创建的应用程序池中的用户标识设置为“networkservice”
- Set the framework version of the newly created application pool to '4.0' - 将新创建的应用程序池的框架版本设置为“4.0”
- I've given the user 'networkservice' full directory permissions to the solution directory - 我已将用户'networkservice'完整目录权限授予解决方案目录

I've also tried several other settings combination, like enabled WindowsAuthentification, FormsAuthentication et cetera. 我还尝试了其他几种设置组合,例如启用WindowsAuthentification,FormsAuthentication等等。 Without luck so far. 到目前为止没有运气。

This is Web tab of the project : 这是项目的Web选项卡
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) 服务器:使用本地IIS Web服务器,项目URL“http:// localhost:86 /”(我也尝试使用“http:// localhost:86”,似乎没有什么区别)

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) (不使用UrlRewrite 2.0模块是没有选择)

And finally the web.config : 最后是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". 更新 :显然我可以使用ActionType =“Rewrite”进行调试,但不能使用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) (到目前为止,我在2台不同的计算机上得到了它

Visual Studio, when starting up, will (for some reason) attempt to access the URL: Visual Studio在启动时会(由于某种原因)尝试访问URL:

/debugattach.aspx /debugattach.aspx

If you have a rewrite rule that redirects (or otherwise catches), say, .aspx files, somewhere else then you will get this error. 如果你有一个重写规则,重定向(或以其他方式捕获),比如.aspx文件,在其他地方,那么你将得到这个错误。 The solution is to add this section to the beginning of your web.config 's <system.webServer>/<rewrite>/<rules> section: 解决方案是将此部分添加到web.config<system.webServer>/<rewrite>/<rules>部分的开头:

<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. 这是一个强大的解决方案,因此请随意将其保存在配置文件中以进行生产。

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. 我刚刚发现,如果您正在使用的项目URL(右键单击您的项目,转到属性,单击左侧的Web选项卡)会触发您的重写规则,然后使用播放按钮进行调试将无法正常工作。 The "fix" is to simply set your project URL to one that won't be rewritten. “修复”只是将项目URL设置为不会被重写的URL。

For example, I am using URL rewrite to make sure that HTTP requests get redirected to HTTPS. 例如,我使用URL重写来确保HTTP请求被重定向到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). 只要我的项目URL以https://开头,那么我就没有问题调试(除了我必须在我的开发机器上安装SSL证书这一事实,但这很容易解决)。

I was having the same problem. 我遇到了同样的问题。 I couldn't start my project to debug in visual studio. 我无法启动我在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. 首先,我必须创建一个规则来忽略页面/debugattach.aspx,就像@Kirk Woll所说的那样。

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. 我的项目指向通过页面“index.aspx”开始操作,我的规则被创建以删除aspx扩展。 So, changing the start page to the page already formatted (with no .aspx) it worked perfectly. 因此,将起始页面更改为已格式化的页面(没有.aspx),它可以完美地工作。

Ps. 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. 1:我的项目中有超过5个规则,我已经逐个隔离以确定导致问题的规则,并且我发现导致问题的规则是删除aspx扩展的规则。

Ps. 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. 2:即使纠正项目开始页面,它仍然无法正常工作,只有在我添加了忽略页面/debugattach.aspx的规则时才有效。

Ps. PS。 3: I hadn't to change any of my rules to match some pattern that I should ignore 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: LowerCaseRule条目应如下所示:

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

我遇到了这个问题,解决方案是将主机名添加到IIS中的站点绑定,然后将项目URL从http更改为https。

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. 我在使用VS 2010,IIS 7和URLRewriter 2时遇到了类似的问题并找到了解决方法 - 但希望有人会为您发布真正的解决方案。

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. 您可以将调试器附加到IIS进程并按如下方式进行调试:1。在Visual Studio中,单击“调试”>“启动而不调试”2.设置断点3.单击“调试”>“附加到进程”。
3. Check the "Show processes in all sessions" checkbox. 3.选中“在所有会话中显示进程”复选框。 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. 4.突出显示w3wp.exe(iis工作进程)并单击“附加”5.在浏览器中,转到将导致断点被触发的URL 6.在Visual Studio中,应在断点处暂停代码你可以照常上班。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM