设为首页 收藏本站
查看: 733|回复: 0

[经验分享] 转: Debug with IIS Express

[复制链接]

尚未签到

发表于 2015-8-13 10:25:00 | 显示全部楼层 |阅读模式
  http://www.intrepidstudios.com/blog/2010/7/11/debug-your-net-web-project-with-iis-express-t.aspx
  Update: IIS Express has been officially released as a standalone installation.
  For those of us too impatient to wait for Visual Studio SP1 to natively support IIS Express, I've done some digging and found a way to [fairly] easily setup a debugging environment for IIS Express and VS 2010 (should work for VS 2008 also, though!). This assumes you are at least an intermediate user of .NET/IIS and Visual Studio.
Prerequisites

  • Download and install IIS Express.
  • Be using Visual Studio 2010 or 2008 and a web project to debug.
Steps to Setup IIS Express
  It's actually quite simple to setup IIS express. Once IIS Express is done installing, go to "My Documents\IISExpress8\config".

  Right-click "applicationhost.config" and open in your favorite text editor.
  Go to line 145. Notice the <sites> element. This is where we can configure our website for IIS Express. Copy the site that is already there and add another entry below it.
  Remove the "autoStart" attribute for the first site.

  This should be self-explanatory, but in case it isn't, we are setting up a root site in IIS:

  • "name" is what you want the website name to be. This can be whatever you want.
  • "id" is just the ID of the site for IIS Express. Increment it.
  • "physicalPath" is the directory your site files are located in, i.e. the root folder of the website. Mine is below:

  • "bindingInformation" is where you set the host name and port you want the site to run in. This can be whatever you need it to be, perhaps if you have a static port set on your VS project.
  • "applicationPool" is the app pool to run under. This is important! If your site is .NET 4, you can use "Clr4IntegratedAppPool". If you are .NET 3.5 or below, you must use "Clr2IntegratedAppPool". Otherwise you will get config errors.
  Let's test it out! Save the config file and close it.
  Go to Run… and type in the following command:
  "C:\Program Files (x86)\Microsoft WebMatrix\iisexpress.exe" /site:{YOUR_SITE_NAME}
  Replace "{YOUR_SITE_NAME}" with the name you gave the site in the config file above. If you are on 32-bit windows, omit the " (x86)" part after Program Files.
  Side Note: You can get a list of command-line switches by going into Command Prompt and typing in "iisexpress /?". You'll notice you can also directly launch any site by physical path and desired port.
  Now open your browser and browse to the URL of your site! Voila, it should work (or not, in my case… but that's because this isn't my dev machine):

  You might want to create a shortcut on your desktop to the run command I had you type in earlier. It will make it a lot easier to start IIS Express when you're developing.
  Note: Now that you've set up this web site, you could manage it from the WebMatrix GUI if you prefer that method for more advanced settings.
Setting up Visual Studio 2010/2008
  Go ahead and open up your solution in Visual Studio.
  Right-click on your web project and go to Properties, then the Web tab. Click the "Start URL:" radio button and put in the path to your site:

  Then below it, click the "Use Custom Web Server:" radio button and again put the path to the URL:

  Next, and this is important, uncheck everything below it. Visual Studio will try to attach to the non-existent IIS server otherwise and not let you debug. We're sort "tricking" it into using IIS Express.
  Save and close the project's properties. Now hit Alt-F8 to open up Macro Explorer. Right-click on the My Macros –> Module 1 node and click "Add Macro."

  Use the following macro:

  Source:



1.Public Sub AttachToIISExpress()
2.For Each process As EnvDTE.Process In DTE.Debugger.LocalProcesses
3.If (process.Name.IndexOf("iisexpress.exe") <> -1) Then
4.process.Attach()
5.End If
6.Next
7.End Sub  
  That is it. The process to follow is:

  • Start IIS Express using the run command/shortcut above.
  • Hit F5 to start debugging. Visual Studio will enter debug mode and start the site in a browser window.
  • Next, run the macro we created to attach to the IISExpress server.
  • Voila, you now can debug not only your solution's code but also any scripts loaded by the browser!

Setting up a Keyboard Shortcut
  If you're like me, right-clicking and running the macro is too much work! So let's create a keyboard shortcut, shall we? How about 'F4'?
  Go to Tools –> Customize… then click the "Commands" tab. Select "Debug" in the "Menu bar:" drop-down.

  Click "Add Command…" and click "Macros" in the left-hand list. Click the IISExpress macro.

  Now just rearrange the list to your liking. You can click the newly added command and then click Modify Selection –> Rename.
  Click Close and close the customize dialog.
  Go to Tools –> Options. Click Keyboard in the left-hand list. Start typing "view.prop" to find the Properties Window keyboard shortcut (already assigned to F4). Hit Remove to get rid of the F4 shortcut.

  Now type in "iis" to filter down to the IIS macro. In the shortcut keys box, hit F4, then Assign.

  All done! Now instead of right-clicking the macro every time, you only need to hit F4 after you hit F5.
Closing Comments
  Remember that this is just a temporary workaround until Scott and his ninja team release a hotfix for Visual Studio to enable native IIS Express integration. I needed this functionality this weekend while working on a project (due to how Cassini handled URL requests and because attaching to IIS 7 for debugging was not working for me).
  I hope this helps some other fellow curious developers. As always, leave a comment if you have a suggestion to streamline this even more (I attempted to wrap the whole debug process into one macro with no success… maybe someone smarter than me can!).
  
  ------------------------------------------------------------------------------------------------
  http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer
  
  Allow incoming connections
  If you’re running Windows 7, pretty much all incoming connections are locked down, so you need to specifically allow incoming connections to your application. First, start an administrative command prompt. Second, run these commands, replacing 192.168.1.42:58938 with whatever IP and port you are using:
  > netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone
  This just tells http.sys that it’s ok to talk to this url.
  > netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=58938 profile=private remoteip=localsubnet action=allow
  This adds a rule in the Windows Firewall, allowing incoming connections to port 58938 for computers on your local subnet.
  And there you go, you can now press Ctrl-F5 in Visual Studio, and browse you site from another computer!
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-98314-1-1.html 上篇帖子: 本周ASP.NET英文技术文章推荐[09/23 下篇帖子: iis 非法关键字过滤器--ISAPI---通配符映射
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表