开发者

How to pass data from Silverlight OOB application to asp.net website?

I created silver-light 4.0 application in that user can enter their username and password.

After submit this secret data(username, password ) from SL application,

it submitted to website with query string..

I want to pass as belo开发者_如何学运维w URL string

for ex: -   http://testsite.com/mypage.aspx?<encrypted string>

I want to pass username and password in encrypted format from SL to Aspx page..

How I pass those information from SL application to asp.net website..


So you could just use the WebClient class and GET the page.

(I'm assuming your doing asp.net WebForms NOT MVC)

Your asp.net page should be a blank page, in your code behind you read your query string and do what you need with it, depending on success or failure you write the appropriate response with Response.Write();.

In your silverlight code, you will just need to request for your page, and you can then read the response from your asp.net page.

Asp.net:

var encyString = Request.QueryString["str"];
//some logic
Response.Write("Success");

Silverlight:

WebClient client = new WebClient(); 
client.DownloadStringCompleted +=
    new DownloadStringCompletedEventHandler(
    client_DownloadStringCompleted);

In Button1_Click, I call DownloadStringAsync, passing the complete URL that includes the number specified by the user.

private void Button1_Click(object sender, RoutedEventArgs e)
{
    string encryptedString = "example";
    client.DownloadStringAsync
      (new Uri("http://testsite.com/mypage.aspx?"+encryptedString));
}

In the DownloadStringCompleted event-handler, I check that the Error property of the event args is null, and either output the response or the error message to the text block.

void client_DownloadStringCompleted(object sender,
  DownloadStringCompletedEventArgs e)
{
    if (e.Error == null)
        resultBlock.Text = "Using WebClient: "+  e.Result;
        //will be Response.Write();

    else
        resultBlock.Text = e.Error.Message;
}

Above code was plagiarized from this blog.

Remember, a sniffer can read your request. You may want to use SSL if you need better security. Possibly a more secure way to send this data would be to POST it to your asp.net page.

This article describes how to POST from silverlight to a page.

HTH


What I understood from the question is that you are authenticating user twice – First in SL app and then in ASP.Net app. Instead can you just authenticate user in SL and pass the result (True/False or token may be) to ASP.Net app? This is the safe way I feel.


You can use like HtmlPage.Window.Eval("window.location.href='"+ YOURURL +"'");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜