Streaming music

davearia

Centurion
Joined
Jan 4, 2005
Messages
184
Hi,

I read this article of few months ago: http://blogs.msdn.com/coding4fun/archive/2006/10/31/913360.aspx. I built my own site based on the code provided. Locally it worked perfect.

The problem is when I put it on my web server and try to access it from the web. There seems to be no playlist showing, where as when it ran locally I got loads of songs. It seems that the problem might be to do with the user. I did some crude experiments by putting some email code so I could see what was going on.

The first one is at page level:
Visual Basic:
Protected Sub lgnAdmin_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles lgnAdmin.Authenticate
        'Create an instance of the MailMessage class.
        Dim objMM As New MailMessage()
        'Set the properties.
        objMM.To = "me@me.co.uk"
        objMM.From = "me@me.co.uk"
        objMM.BodyFormat = MailFormat.Html
        objMM.Priority = MailPriority.High
        'Set the subject.
        objMM.Subject = "User/Password"
        'Set the message.
        objMM.Body = "Your user name is: " & User.Identity.Name
        'Send the message, use the Send method of the SmtpMail class.
        SmtpMail.Send(objMM)
        If Me.lgnAdmin.UserName = System.Configuration.ConfigurationManager.AppSettings("UserName").ToString And Me.lgnAdmin.Password = System.Configuration.ConfigurationManager.AppSettings("Password").ToString Then
            Response.Redirect("Admin.aspx")
        Else
            Me.lgnAdmin.InstructionText = "Sorry, your login details do not match!"
        End If

The second one is in the database class provided by coding 4 fun:
Visual Basic:
Private Shared Sub Refresh()
		Dim wmp As WindowsMediaPlayer = New WindowsMediaPlayer
        Dim playlist As IWMPPlaylist = wmp.mediaCollection.getAll()
        'Create an instance of the MailMessage class.
        Dim objMM As New MailMessage()
        'Set the properties.
        objMM.To = "me@me.co.uk"
        objMM.From = "me@me.co.uk"
        objMM.BodyFormat = MailFormat.Html
        objMM.Priority = MailPriority.High
        'Set the subject.
        objMM.Subject = "User/Password"
        'Set the message.
        objMM.Body = "Your user name is: " & My.User.Name & "<br/>Playlist count is: " & playlist.count.ToString
        'Send the message, use the Send method of the SmtpMail class.
        SmtpMail.Send(objMM)
		Dim artistDictionary As Dictionary(Of String, Artist) = New Dictionary(Of String, Artist)

		For i As Integer = 0 To playlist.count - 1
			Dim media As IWMPMedia = playlist.Item(i)
			Dim albumArtistName As String = media.getItemInfo("AlbumArtist")
			Dim albumName As String = media.getItemInfo("Album")
			Dim trackName As String = media.getItemInfo("Title")
			Dim trackLocation As String = media.getItemInfo("SourceUrl")
			Dim trackNumberString As String = media.getItemInfo("OriginalIndex")

			Dim theArtist As Artist
			Dim artistSortName As String = Artist.GetSortName(albumArtistName)

			If Not artistDictionary.TryGetValue(artistSortName, theArtist) Then
				theArtist = New Artist(albumArtistName)
				artistDictionary.Add(artistSortName, theArtist)
			End If

            Dim theAlbum As AppCode.Album

			If Not theArtist.Albums.TryGetValue(albumName, theAlbum) Then
                theAlbum = New AppCode.Album(albumName, theArtist)
				theArtist.Albums.Add(albumName, theAlbum)
			End If

			Dim theTrack As Track

			If Not theAlbum.Tracks.TryGetValue(trackName, theTrack) Then
				Dim trackNumber As Integer

				If Integer.TryParse(trackNumberString, trackNumber) Then
					theTrack = New Track(trackNumber, trackName, trackLocation)
				Else
					theTrack = New Track(trackName, trackLocation)
				End If

				theTrack.Album = theAlbum
				theAlbum.Tracks.Add(trackName, theTrack)
			End If
		Next

		ArtistList.AddRange(artistDictionary.Values)
		ArtistList.Sort()
	End Sub

When I ran it in visual studio I got a user and lots of songs in the playlist. Running it from IIS I got no user and no playlist.

I have read impersonation articles and tried adding the following to my web config:
Visual Basic:
<identity impersonate="true" userName="machine\me" password="pass"/>
After adding this the email logging still the user as blank.

Also read various articles such as: http://msdn2.microsoft.com/en-us/library/xh507fc5(VS.71).aspx. Up to now I stumped.

I wanted to add this to part of my site (with a login page to stop public access) so I could access all my music on my server at home from work.

Can anyone please help.

Dave.
 
One gotcha when using the built in web server compared to IIS is security ;) the built in server will always run with you as a logged in user, IIS will only log you in if security is configured to require a user to be logged in.

Depending on what security model you are using you can fix it one of a couple of ways...

If you are using Windows Integrated Authentication then you could disable anonymous access under IIS. Alternatively if you are using Forms authentication then you can require all users to be logged in through the web.config file's authorization section (basically you need to add a <deny users ="?" /> entry)
 
The stream dies not flow yet!

Hi,

Tried both ways but still no luck.

Attempt 1 Windows Authentication. Here is what IIS 5 security looks like:

windows.jpg


Here is the relevant part of web config:

Visual Basic:
<system.web>
		<httpHandlers>
			<add path="*.wpl" type="PlaylistCreator" verb="*" validate="false" />
			<remove verb="*" path="*.asmx"/>
			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
		</httpHandlers>
		<httpModules>
			<add name="WindowsAuthentication"
			  type="System.Web.Security.WindowsAuthenticationModule" />
			<add name="FormsAuthentication"
			  type="System.Web.Security.FormsAuthenticationModule" />
			<add name="PassportAuthentication"
			  type="System.Web.Security.PassportAuthenticationModule" />
		</httpModules>
		<siteMap defaultProvider="MusicSiteMapProvider">
			<providers>
				<add name="MusicSiteMapProvider" type="MusicSiteMapProvider" />
			</providers>
		</siteMap>
		<compilation debug="true"/>
		<authentication mode="Windows"/>
		<authorization>
			<allow users="MACHINE\ME" />
			<deny users="*" />
		</authorization>
	</system.web>

I am given a windows login screen at which I put in my normal windows login details. It fails 3 times and then shows the You are not authorized to view this page page.



Attempt 2 Forms Authentication. Here is what IIS 5 security looks like:

forms.jpg


Here is the relevant part of web config:

Visual Basic:
<system.web>
		<httpHandlers>
			<add path="*.wpl" type="PlaylistCreator" verb="*" validate="false" />
			<remove verb="*" path="*.asmx"/>
			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
		</httpHandlers>
		<httpModules>
			<add name="WindowsAuthentication"
			  type="System.Web.Security.WindowsAuthenticationModule" />
			<add name="FormsAuthentication"
			  type="System.Web.Security.FormsAuthenticationModule" />
			<add name="PassportAuthentication"
			  type="System.Web.Security.PassportAuthenticationModule" />
		</httpModules>
		<siteMap defaultProvider="MusicSiteMapProvider">
			<providers>
				<add name="MusicSiteMapProvider" type="MusicSiteMapProvider" />
			</providers>
		</siteMap>
		<compilation debug="true"/>
		<authentication mode="Forms">
			<forms loginUrl="Homepage.aspx"
				   protection="All"
				   timeout="30"
				   name=".ASPXAUTH"
				   path="/"
				   requireSSL="false"
				   slidingExpiration="true"
				   defaultUrl="Homepage.aspx"
				   cookieless="UseDeviceProfile"
				   enableCrossAppRedirects="false" />
		</authentication>
		<authorization>
			<deny users="?" />
		</authorization>
	</system.web>

Again, I am given a windows login screen at which I put in my normal windows login details. It fails 3 times and then shows the You are not authorized to view this page page.

One other point, when I publish this site for IIS to run I stop the site in IIS and re-start it. Are there any other steps I am missing out?

Please help if you can.

Thanks, Dave.
 
Is this possible?

Hi,

I found that impersonation is not the problem. I put this is my config:
Visual Basic:
<authentication mode="Windows"/>
		<identity impersonate="true" userName="MCH_NAME\ME" password="pasword"/>

Then I put this code in my page:
Visual Basic:
 Dim username As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name
        Me.Label1.Text = "Users name is: " & username

The impersonation worked when I browsed the site through IIS. The user was as the config file stated, however the playlist is still empty.

Do you think that trying to access my music collection stored on my web server from a machine via the internet is possible or am I wasting my time?

If it is at all possible what should I check as the cause of the playlist being empty.

I really would appreciate some help as I have been trying to do this for a while now.

Dave.
 
Re: Is this possible?

Try changing the config file so the authorization looks like

[highlight=xml]
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
[/highlight]
 
Hi,

So my config has this in it:
Visual Basic:
<authentication mode="Windows"/>
		<identity impersonate="true" userName="MchName\ME" password="password"/>
		<authorization>
			<deny users="?" />
			<allow users="*" />
		</authorization>

In IIS I have set anonomous access off & turned integrated windows authentication on. I try to browse to the site through ISS and I am asked for my login details.

I enter these and the site hangs for a few seconds. The login box appears again this time the username is filled with the IP of the machine followed by a backslash and the mu username i.e. my fully qualified username. I enter my password. The box is shown again and I enter my password for the third time.

After this I get:
You are not authorized to view this page
You do not have permission to view this directory or page using the credentials you supplied.

I don't know what it is that I have done but obvioulsy something is wrong.

Please help if you can!:D

Dave.
 
I am sorry but can you tell me how I would find the information out?

I looked at the properties of the folder and nothing too obvious.

Thanks, Dave.
 
Back
Top