Question

I am attempting to do the following but am not sure if I am going about this the correct way. As mentioned in the title, I am using asp.net mvc 4.

  • From a page, I am making an ajax request to the server. The ajax request calls the follow function.

    public ActionResult VideoFeed()
    {
        // Create a new 'HttpWebRequest' Object to the mentioned URL.
        HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://url/cgi/image.php?type=live");
    
        // Digest Authenticate
        myHttpWebRequest.Credentials = new NetworkCredential(username, password);
    
        // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
        HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
    
        // Store headers
        string authorization = myHttpWebRequest.Headers["Authorization"];
        string host = myHttpWebRequest.Headers["Host"];
    
        // Add header
        Response.AppendHeader("Authorization", authorization);
        Response.AppendHeader("Host", host); 
    
        return PartialView("~/Views/RedLight/SystemStatus/_Video.cshtml");
    }
    
  • In this this function I am attempting to perform a digest authentication using a HttpWebRequest

  • This appears to authenticate fine and I am able to parse the headers.

  • You will then notice that I am attempting to append those headers to the current page that is making this request.

  • Finally I am calling a partial view to return to the current page. The partial view has nothing else except an img tag with a src attribute equal to the url that is present in the function above.

This is not working as I hoped it would. After viewing the net traffic in firebug, I believe it is making the request, adding headers to only that request, calling the partial view and the partial view then again needs to authenticate hence the pop up again popping up for a username and password.

So, yeah. I am having a bit of trouble visualizing how to make this work and would greatly appreciate any advice.

Best,

Chad

Was it helpful?

Solution

After a bit more research, I have come to realize my methods won't work. Instead I need to create a proxy method. I.E. Client calls my server -> my server calls url -> my server streams to client.

I have posted a follow up question at - https://stackoverflow.com/questions/19687534/how-to-properlly-handle-a-webrequst-and-display-it-to-page-video-stream

Thanks,

Chad

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top