R – Calling WMPLib.mediaCollection methods from ASP.NET on IIS return empty lists

impersonationwmplib

I am trying to access a Windows Media Player library from ASP.NET.

The following code:

WMPLib.WindowsMediaPlayer mplayer = new WMPLib.WindowsMediaPlayer();

WMPLib.IWMPStringCollection list = mplayer.mediaCollection.getAttributeStringCollection("artist", "audio");

Returns an non-empty list when run using the VS2005 development web server but an empty list when using IIS.

Setting impersonation with:

System.Security.Principal.WindowsImpersonationContext impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

Doesn't help. It seems that WMPLib still doesn't thinks its running as a user who has a library.

Is there a way to get around this?

Best Answer

Have you tried configuration via web.config in ASP.NET? When you're running in the VS2005 debugger, you're (probably) running code as yourself, but when under IIS you'll be running it as IUSR_machinename or another low-permission system account.

Try adding something like this to your web.config file:

<system.web>
<identity impersonate="true" userName="MYDOMAIN\myuser" password="p@ssw0rd" />
</system.web>

No idea whether this works with Media Player specifically, but it works for other identity/security related problems like this.

Related Topic