views:

343

answers:

2

I'm creating an asp.net MVC app, first time I've done this. I have a flash component I need to use in a view. I have included the SWF files etc in the Contents folder and referenced it from my view, the flash file loads when you get to the view, great.

The problem occurs because the flash file references and XML file for its configuration data, and I'm getting an error accessing that XML file. I'm guessing this is because flash is looking for a relative path and is using the URL for the page, which is obviously an MVC url and so does not refer to an actual location on disk, so the XML file is not there.

I guess the obvious answer is the alter the flash file to look in the contents folder for the XML file, but that means re-compiling the flash, and I know very little about flash so I'd like to avoid doing that. So is there any way to get the XML file to show up in the same URL as the view, so at the moment, the page with the flash component on is located at htttp://localhost/upload/ so I guess the XML file needs to be accessible from http://localhost/upload/flash-settings.xml?

If there's any other better way to do this, without editing the flash file, im open to that too,

+1  A: 

You'll need to either set the routing mechanism to allow for direct files access to the /upload/ folder, or create a Controller Action which will return an XML stream (dynamic or the one read from the physical XML file), and point your SWF to that Route. I'd go with the second option, as it is much flexible.

synhershko
+2  A: 

Add this Action to the FlashUpload Controller:

public class FlashUploadController : Controller
{
    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult FlashSettings()
    {
        var fileName = Server.MapPath("~/Contents/flash-settings.xml");

        return new FilePathResult(fileName, "text/xml");
    }
}

And this route to the RouteTable:

routes.MapRoute("FlashSettings", "upload/flash-settings.xml",
    new { Controller = "FlashUpload", Action = "FlashSettings" });
eu-ge-ne
Fantastic, that got the XML working from that URL, thanks! Flash still doen't like it, but I guess I'll have to keep looking.
Sam Cogan
Exactly what I was looking for. Thank you.
Jack Marchetti