Problems with mediaElement.Source and absolute path - asp.net

I have a SL project that is simply the MediaElement. I embed this in my aspx page and do all the controling of the element from the aspx page throught the java to managed code bridge. I had all my video files in the project as resources for testing but now want to move them out to the server where they will live. The server is in a different domain from my development box but I have access. I can see my files by going to the "run" command and typing that path as follows: "\mediaserver.otherdomain.com\Content\MyVideo.wmv" I can access the folder and view the video's fine from my computer. However, when I do my
`mediaElement.Source = new Uri(MediaPath, UriKind.RelativeOrAbsolute);`
in my code to load the video into Silverlight video does not play. The Media path is "\MediaServer.OtherDomain.com\Content\MyVideo.wmv. I have image files that I reference using the same path "\MediaServer.OtherDomain.com\Content\MyVideo.jpg" and they display fine.
When I debug and look at the values set in the .Source propery I see:
Absolute Path = "/Content/MyVideo.wmv"
Absolute Uri = "file://MediaServer.domain.com/Content/MyVideo.wmv"
Host = "MediaServer.domain.com"
This all looks good, so why don't I see the video?

Silverlight does not allow you to use cross domain references out of the box. You need to add an exception to do so.
If you're using SL4, look at Making a Service Call Across Domain Boundaries

Related

What is the best way to show an image (which is in local machine) in picturebox

I'm working on a project in ASP.NET but I'm stucked in this case;
I have ten thousands of images in local machine. I need to show them in the picturebox in ASP.Net. I can not copy all images to web appliation folder. So I have to give the file path like
\\server\something\something.jpg
But it doesnt work of course.
I found some solutions but they are not so clear, so I didnt manage to success.
So what should I do ?
In IIS, define a virtual sub-directory in your site, with directory's physical location being \\server\something. Then you will be able to specify image virtual url as ~/something.jpg.
Use code-behind to return images (aspx page or ashx handler) - then, with enough permissions given to IIS user, the web application will read the required image and put it in response stream.

How to display image which is stored in local drive?

I have a asp page in which i have to display the image which is stored in my local disk C:
i.e..
C:\Program Files\Adrenalin\Adrenalin\UploadedFiles\TemplateFile\abc.jpg
how can i do that...i am not able to do so.
the image is not displayed instead it shows a empty image holder with the name of the image as specified and URL as not available.
Please help....
You will have problems with permissions if the image is outside of the web site folder. Traditionally, web sites run under the NETWORK SERVICE user account, which will limit access to files outside of the folder. You will need to extract the file from a folder with similar access and it is extremely unwise to do so, particularly from Program Files.
You should possibly proxy the file via a web page or web service, which doesn't expose the fact that the image is served external to the web site. You'll need to make sure the target folder C:\Program Files\Adrenalin\Adrenalin\UploadedFiles\TemplateFile has NETWORK SERVICE Read-access.
eg. create a blank ASP.NET page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ImageServer.aspx.cs" Inherits="ImageServer" %>
with the code behind:
class ImageServer
{
void Page_Load(object sender, EVentArgs e)
{
Response.ContentType="image/jpeg"; // for JPEG file
string physicalFileName=#"C:\Program Files\Adrenalin\Adrenalin\UploadedFiles\TemplateFile\abc.jpg";
Response.WriteFile(physicalFileName);
}
}
And test in your browser by going to the URL
http://<localhost>/<website>/ImageServer.aspx
You should get the image.
Then, within the tag, use the URL of the page as your image placeholder:
<img src="ImageServer.aspx" alt="Image served" />
UPDATE:
Looking at your latest comments, I suggest you send a QueryString parameter with some sort of employee code and use that to query the database and get the appropriate filename within the Page_Load() method. Don't send the filename as part of the QueryString.
What you're trying to do can work, but it's highly discouraged in Web development. Putting the permissions problems aside (which are very serious), you can never assume that your images will be available in the absolute path you provided on drive C:.
What you should do, is create a folder inside your website directory and use it to store the images, and use relative links instead of absolute links.
Even if you manage to make absolute links work now, prepare yourself for sever headaches in the future when running your application in different configurations.
copy the image in your project root folder and provide the image source as only the name of the image instead of the complete path.
e.g., img src = "battlefield.jpg"

How can I configure my data services in Flex to call the same domain that the SWF was served from?

I've got an HTTP service I defined in Flash Builder, via the "Data Services" tab. I've got an absolute URL in there right now.
What I really want is to not define a path that includes a domain name at all--I want the service to simply call an absolute path that's on the same domain as whatever domain the SWF was served from... can I do that? When I got rid of the base URL and then gave an absolute URL path (e.g., /roster/deleteMember), Flex Builder complained that "File does not exist." Well, of course it doesn't exist, it isn't a file, it's a URL to a service call--there is no corresponding file on the filesystem.
Can anyone advise me how to do that? If I change the domain name, it wipes out all the parameter definitions for the methods, so I have to go back to each method and setup the parameters again. Rather a headache.
Now, I would have thought this would work. from the adobe documentation:
The configuration files sometimes contain special {server.name} and {server.port} tokens. These tokens are replaced with server name and port values based on the URL from which the SWF file is served when it is accessed through a web browser from a web server. Similarly, a special {context.root} token is replaced with the actual context root of a web application.
So, if you specify the endpoint as
http://{server.name}:{server.port}/{context.root}, then
automatically on runtime, the variables are set by the flashplayer depending on where you've been downloaded the application.
Sounds great... but it's not working for me. I can't even set those values in the Flash Builder Data Services tool. Here's a recording of what I'm getting.
http://screencast.com/t/MTk0NzNiYzY
I'm not sure it's possible from the DS window.
If you were doing it in code, you could use Application.application.url to get where the swf had been loaded from.

ImageUrl trying to display an image outside of project root

I am working with two different web sites in asp.net. In the first project i upload some images to a specific folder under the project root and save just the filename in the database, now i am trying to display this images at some page of the second project I know the filename from the database and the image folder as absolute pat but I have not been able to display the image, even thought when looking in firebug the image src is correct src="D:/MyFolder/image.jpg" the image does not display, probably because it is not pointing in the right directory.
I have also tried using Server.MapPath and then my D location but still no success.
I am sure someone has faced the same situation before and was really hoping to get some hint to manage this.
Thank you in advance
I found my solution, strange but i didn't catch it before. Uploaded pictures under a project can always be accessed using the url of the project http://www.yourwebsite.com/images/photo.png now in the second project you can use reference the images using this url and concatenating the file name which i store on database. I think this is the best solution and without changing the code access security which i think can bring other problems with it. Anyway thank you guys.
If you want to display the image that is not in your project (I mean it is present in some other project or some other drive) just create the virtual directory in IIS
Go to "Run", type inetmgr
Right click on your project and add virtual directory
Give alias name and path so that it acts like folder in your project
I don't think you can serve files outside of your application path by default. It's called Code Access Security. You can read up on it here:
http://msdn.microsoft.com/en-us/library/930b76w0.aspx
You can fix this by changing your trust level to High in your web.config:
http://msdn.microsoft.com/en-us/library/tkscy493.aspx
I wouldn't recommend doing this for any site that is externally accessible. In fact, depending on how/where you're hosting your application, this option may be restricted.
You can only "link" to files that exist relative to the same project or are hosted on another site via an absolute URL.
If you want to service files outside the application/website (on disk or in a database) you will need to build a mechanism that gets the file and binary writes it to the browser, setting the MIME type etc. This is best done using an HttpHandler.

Where does the ASP.NET development server get its images from?

In my web application I dynamically generate images and want to show the images as part of a web page.
But, when debugging using the ASP.NET development server (not IIS) - I have no idea where to store these images so they can be referenced from my web application.
Should I use Directory.GetCurrentDirectory()?
Or Assembly.GetExecutingAssembly().Location?
Or Assembly.GetExecutingAssembly().CodeBase?
None of these paths seem to work.
Any ideas?
Server.MapPath("~/") will give you the path the the root of the web application. Everything placed within the scope of this path should be automatically exposed by the web server, be it IIS or the VS devevelopment server.
The Server property is available in to all Page objects, and can otherwise be found on the HttpContext.
You can use
Server.MapPath()
You can write ashx handler to server images on the fly. Here is tutorial for this. It you want to generate and display them later then create a folder in your web-site folder tree and get its physical path using this:
string imgPath = Server.MapPath("/") + "Images\" + IMAGENAME;
Make a seprate aspx page, and put your code overthere that create your dynamic images..
your code should be look like....
Response.ContentType = dtblProductImage[0].ImageFileExt;//image extension
Response.BinaryWrite(dtblProductImage[0].ImageData); //your image binary
now go to that page where you want to show your image and set the image property of imageURL to your page, it will look like this....
<asp:Image ID="imgProduct" runat="server" ImageUrl="yourpage.aspx" />

Resources