WebApi Deployed to Azure - Controllers Don't W

2019-07-17 11:18发布

I have a WebApi project that wraps the Dynamics CRM Online web service and provides a REST api. I have a simple controller that gets some contacts from CRM and returns them to the caller.

Everything works fine when I run it in the local emulator. However, when I deploy the project to Azure, I can reach the home page, but the controllers all return http 500 errors. Why would this happen? And how can I troubleshoot to get more details?

UPDATE

The issue is with the absence of Microsoft.IdentityModel.dll on the Server 2012 instance running the web role in Azure. I found this by opening web role instance in RDP, installing Fiddler, and making the request from Fiddler to the local IIS server. It responded with the detailed error.

Now my issue is figuring out how to enable IdentityModel on a Windows Azure Web Role. You're supposed to be able to add it via the Server 2012 Add Roles and Features wizard, but it's totally locked down on the Web Role. You can't check any boxes that aren't already checked. Is this even possible?

1条回答
Evening l夕情丶
2楼-- · 2019-07-17 11:56

The issue is giving the Web Role access to Windows Identity Foundation when it's inherently not there. Marc Schweigert provides clear steps to do this here:

http://blogs.msdn.com/b/devkeydet/archive/2013/01/27/crm-online-amp-windows-azure-configuring-single-sign-on-sso.aspx

Go to the 23:00 mark of the video and you'll see the 4 necessary steps:

  1. Reference Microsoft.IdentityModel.dll (need WIF SDK installed) a. Set copy local = true
  2. Create RegisterWIFGAC.cmd in your web role project
  3. Create Startup Task in ServiceDefinition.csdef that invokes RegisterWIFGAC.cmd
  4. Add GacUtil to the project (used in the startup task) to put Microsoft.IdentityModel.dll in the GAC every time the web role starts).
查看更多
登录 后发表回答