views:

719

answers:

2

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?

+1  A: 

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.

Dylan Beattie
A: 

I've run into a similar problem: the code works fine on my local machine, but once deployed on my home server, it can not pull anything out of the media library (I can open media player to verify there are songs in the library)

At first I thought it was a process issue as well, so I tried both setting the application pool to run under my own account, and to set it via the identity impersonate tags; neither resolved the issue.

I'm not sure of what other differences would cause the issue

John