Cross-domain policy issue in Silverlight application

Error:
“An error occurred while trying to make a request to URI. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.”

1. Create an xml file using notepad and save as clientaccesspolicy.xml with the following content.

<?xml version=”1.0″ encoding=”utf-8″?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers=”SOAPAction”>
        <domain uri=”*”/>
      </allow-from>
      <grant-to>
        <resource path=”/” include-subpaths=”true”/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>
2. Create an xml file using notepad and save as crossdomain.xml with the following content.
<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd”>
<cross-domain-policy>
  <allow-http-request-headers-from domain=”*” headers=”SOAPAction,Content-Type”/>
</cross-domain-policy>
3. Copy these 2 files into web site root folder for example, c:\inetpub\wwwroot. for your IIS (local system) or in root folder of website(c:\inetpub\wwwroot\controlsdemowcf)  on server (2008, 2003).

Easily Deploy Your LightSwitch Apps to Azure Websites in Minutes

As part of my demo preps for all the conferences I’ve spoken at recently I’ve been deploying my LightSwitch apps to Azure websites and I can honestly say that it is by far the easiest way to get a LightSwitch application up and running. Of course you can always manually set up your own server, database and network if you want a purely internal business app like I’ve showed in these deployment posts. However, it’s always hard to troubleshoot what goes wrong when a deployment goes bad because everyone’s environment is a little bit different. The great thing about Azure websites is the environment is hassle-free and already ready for you to deploy your LightSwitch applications.

In this post I’ll detail step-by-step how to deploy a LightSwitch application to Azure websites. But first, you may be wondering what the heck is an Azure website and what’s the difference between that and a cloud service? LightSwitch applications can be deployed to both through the Publishing Wizard, but why would you choose one over the other?

Azure Cloud Services provide reserved, infinitely scalable, n-tier options running on a Platform as a Service (Paas). Azure Websites are for quick and easy web application and service deployments. You can start for free and scale as you go. So if you do not need all the other services like caching, blob storage, CDN, etc. that the Azure cloud services provide and you only have a LightSwitch application to deploy, then an Azure website is the right choice.

If you’re interested in deploying to cloud services see Andrew & Brian’s post: Publishing LightSwitch Apps to Azure with Visual

For detail click here

How add two xaml to aspx page

You can have one Silverlight application project (one xap file).  Assume it contains two UserControls Page1.xaml and Page2.xaml, and you want Page1 to be shown in Silverlight Control1, and Page2 to be shown in Silverlight Control2 in the same aspx page.

You can use initParams in the Silverlight control tag to indicate which UserControl you want to use as the application start up page:

Code in App.xaml Application_Startup:

private void Application_Startup(object sender, StartupEventArgs e)
{

if(e.InitParams.ContainsKey[“Page”])

{

string page = e.InitParams[“Page”];

if(page == “Page1”)

this.RootVisual = new Page1();

if(page == “Page2”)

this.RootVisual = new Page2();

}

}

Send free SMS API

http://ubaid.tk/api-usage/

Required Params : uid, pwd, phone, msg.

uid : your userid for the required sms provider
pwd : your password for the required sms provider
provider : way2sms(default), fullonsms, smsindia, whozzat, smsinside, site2sms. if you do not specify any provider, way2sms will be used by default.
phone : phone number whom you want to send sms. seperate multiple phone numbers with a comma (,)
msg : your sms message, unlimited chars. will be sent as multiple msgs if crosses the message length for any provider

Optional Parameters
codes : 1. Send this if you require a user friendly msg from the server. for example, if codes=1 is not provided the server will return the result as an integer.
1 – SMS sent
-1 – Server Error
-2 – Invalid Username
-3 – Invalid message text
-4 – Login Failed
-5 – IP Blocked

JavaScript to redirect to https


function RedirNonHttps() {
    if (location.href.indexOf("https://") == -1) {
        location.href = location.href.replace("http://", "https://");
    }
}

Then, simply call the RedirNonHttps function on page load :

onload="RedirNonHttps();"

Upload video on youtube from asp.net website

Download you-tube API dll from: Here. Add below code on upload button:

YouTubeRequestSettings setting = new YouTubeRequestSettings("app name anything u like", "Your Developer Key", "Your youtube username", "youtube a/c passowrd");
YouTubeRequest request = new YouTubeRequest(setting);

Video newVideo = new Video();

newVideo.Title = "My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",YouTubeNameTable.DeveloperTagSchema));

newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");

newVideo.YouTubeEntry.MediaSource = new MediaFileSource("D:\\Demo\\YoutubeVideoUpload\\e3a6f15f-4a8c-40d5-9cc8-c45d30b7f9ed.mov", "video/quicktime");
Video createdVideo = request.Upload(newVideo);

Retrieve uploaded videos

videos.aspx.cs :

private string YouTubeChampionshipChannel;
        private string YouTubeClientID;
        private string YouTubeDeveloperKey;
        public string YouTubeMovieID;
        public DataTable dtVideoData = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            //Pass User Name to the YouTube link
            YouTubeChampionshipChannel = "prakashrthd";

            //Add the YouTube Developer keys.
            //Register a Developer Key at: http://code.google.com/apis/youtube/dashboard
            YouTubeClientID = "prakashrthd@gmail.com";
            YouTubeDeveloperKey = "AI39si4EpdRFuvaGm8WNIBIHPmpSfiT7Qmy_WIfhDz3OrLmTwqS0lX_8lcCmBTKq-spys_TfQ8ysWRyg9kB5nFYCifmzgPlFKw";

            CreateVideoFeed();

            //Assign the first video details on page load.
            if (String.IsNullOrEmpty(YouTubeMovieID))
            {
                YouTubeMovieID = dtVideoData.Rows[0]["VideoID"].ToString();
                lblDescription.Text = dtVideoData.Rows[0]["Description"].ToString();
            }

        }

        private void CreateVideoFeed()
        {
            YouTubeRequestSettings settings = new YouTubeRequestSettings("prakashtest", "AI39si4EpdRFuvaGm8WNIBIHPmpSfiT7Qmy_WIfhDz3OrLmTwqS0lX_8lcCmBTKq-spys_TfQ8ysWRyg9kB5nFYCifmzgPlFKw", "prakashrthd@gmail.com", "!loveyougod");
            YouTubeRequest request = new YouTubeRequest(settings);

            //Link to the feed we wish to read from
            string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published", YouTubeChampionshipChannel); ;

            dtVideoData.Columns.Add("Title");
            dtVideoData.Columns.Add("Description");
            dtVideoData.Columns.Add("DateUploaded");
            dtVideoData.Columns.Add("Ratings");
            dtVideoData.Columns.Add("NoOfComments");
            dtVideoData.Columns.Add("VideoID");
            dtVideoData.Columns.Add("Duration");

            DataRow drVideoData;

            Feed videoFeed = request.Get(new Uri(feedUrl));

            //Iterate through each video entry and store details in DataTable
            foreach (Video videoEntry in videoFeed.Entries)
            {
                drVideoData = dtVideoData.NewRow();

                drVideoData["Title"] = videoEntry.Title;
                drVideoData["Description"] = videoEntry.Description;
                drVideoData["DateUploaded"] = videoEntry.Updated.ToShortDateString();
                drVideoData["Ratings"] = videoEntry.YouTubeEntry.Rating == null ? "0" : Convert.ToString(videoEntry.YouTubeEntry.Rating.Average);
                drVideoData["NoOfComments"] = Convert.ToString( videoEntry.CommmentCount);
                drVideoData["VideoID"] = videoEntry.YouTubeEntry.VideoId;
                drVideoData["Duration"] = Convert.ToString(videoEntry.YouTubeEntry.Duration.Seconds);

                dtVideoData.Rows.Add(drVideoData);
            }

            repVideoList.DataSource = dtVideoData;
            repVideoList.DataBind();
        }

        protected void repVideoList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drVideo = (DataRowView)e.Item.DataItem;

                LinkButton showVideo = (LinkButton)e.Item.FindControl("btnShowVideo");
                Literal title = (Literal)e.Item.FindControl("Title");
                Literal description = (Literal)e.Item.FindControl("Description");
                Literal ratings = (Literal)e.Item.FindControl("Ratings");
                Literal noOfComments = (Literal)e.Item.FindControl("NoOfComments");
                Literal duration = (Literal)e.Item.FindControl("Duration");

                showVideo.CommandArgument = drVideo["VideoID"].ToString();
                title.Text = drVideo["Title"].ToString();
                description.Text = drVideo["Description"].ToString();
                ratings.Text = drVideo["Ratings"].ToString();
                noOfComments.Text = drVideo["NoOfComments"].ToString();
                duration.Text = drVideo["Duration"].ToString();

            }
        }
        protected void repVideoList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            // Pass the YouTube movie ID to flash
            YouTubeMovieID = e.CommandArgument.ToString();

            if (YouTubeMovieID == e.CommandArgument.ToString())
            {
                lblDescription.Text = ((Literal)e.Item.FindControl("Description")).Text;
            }

        }

Download full source code: here