Solved

flash and .net

Posted on 2009-05-11
14
302 Views
Last Modified: 2013-11-08
Hi

I have the flash file

and I am submitting the values through flash

How can I get that value from flash to .net
0
Comment
Question by:KaranGupta
  • 8
  • 6
14 Comments
 
LVL 11

Expert Comment

by:azarc3
ID: 24356240
You need to build a page or service to receive those values, just like you would normally.
You'll need to make sure you set your method in Flash sends a POST submission.

After you've done that you can use the normal Request.Form.Item("{form variable name}") to get at the value. Note: They WILL come across as strings.
0
 

Author Comment

by:KaranGupta
ID: 24356271
But debugger is not coming on Page_Load

when submit button is clicked in flash
0
 
LVL 11

Expert Comment

by:azarc3
ID: 24356353
The Flash ActiveX control lives outside of the .NET Framework (IIS and the ASP.NET Worker Process too, really), so typically you won't be able to DEBUG anything the POST operation until it hits the receiving code... You actually might be able to identify the process that is Flash but I wouldn't waste any time on that.  :)

1. As long as the page you're posting to is on a server that you have Remote Debugging rights to you'll be able to debug the "receiving" side of the POST just fine.

2. If #1 doesn't apply then I suggest that you setup a temporary page on your local workstation, run it in debug mode, and point your Flash movie at that until you're confident and comfortable with the result. Once you're good with that (and assuming the fields on your test page are the same as the "production" page will assume are coming in on the POST operation) all you'll have to do is switch the target address in the Flash movie.
0
 

Author Comment

by:KaranGupta
ID: 24356460
can you give me some website in which it is explained with example
0
 
LVL 11

Expert Comment

by:azarc3
ID: 24356478
Sure... which version of Flash are you using?
0
 

Author Comment

by:KaranGupta
ID: 24356486
Flash 9.0
0
 
LVL 11

Expert Comment

by:azarc3
ID: 24356768
Here's what's necessary on the Flash side:
http://www.actionscript.org/resources/articles/559/1/Send-Mail-with-PHP-ASP-or-Perl/Page1.html
- Notes:
  + You only need to read page 1.
  + This should work for either ActionScript 2.0 or 3.0.

Here's what you need for the ASP.NET side:
http://www.asp.net/learn/videos/video-416.aspx (video tutorial)

Example code is below. Notice that I'm suggesting you use a custom handler; you don't need a full page for this, and it gives you more control of the response back to Flash. Note, this is only a simple example... you'll need to adjust it to fit your form fields and anything else you want to add.
<%@ WebHandler Language="VB" Class="EmailHandler" %>
 

Imports System

Imports System.Web

Imports System.Net.Mail
 

Public Class EmailHandler : Implements IHttpHandler

    

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        

        'Create instance of main mail message class.

        Dim mailMessage As MailMessage = New MailMessage()
 

        'Configure mail mesage

        

        'Set the From address with user input

        mailMessage.From = New MailAddress(Request.Form.Item("{the 'from' emaill address field}"))
 

        'Set additinal addresses

        mailMessage.To.Add(New MailAddress(Request.Form.Item("{the address of the intended recipient}").Trim())
 

        'same syntax for the following 

        'mailMessage.CC

        'mailMessage.Bcc

        'mailMessage.ReplyTo
 

        'Set additional options

        mailMessage.Priority = MailPriority.High

        'Text/HTML

        mailMessage.IsBodyHtml = False
 

        'Set the subjet and body text

        mailMessage.Subject = Request.Form.Item("{the 'subject' field from the form}").Trim()

        mailMessage.Body = Request.Form.Item("{the 'message or body' field from the form}").Trim()
 

        'Create an instance of the SmtpClient class for sending the email

        Dim smtpClient As SmtpClient = New SmtpClient()
 

        'begin your response back to Flash

        context.Response.ContentType = "text/plain"
 

        'Use a Try/Catch block to trap sending errors

        'Especially useful when looping through multiple sends

        Try

            smtpClient.Send(mailMessage)

            context.Response.Write({whatever you want your success message/flag to be})
 

        Catch smtpExc As SmtpException

            context.Response.Write({whatever you want the appropriate message/flag to be})
 

        Catch ex As Exception

            ' if you get here, this is bad; something else is going on and you'll need to debug it

            context.Response.Write({whatever you want the appropriate message/flag to be})
 

        End Try
 

    End Sub

 

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable

        Get

            Return False

        End Get

    End Property
 

End Class

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:KaranGupta
ID: 24360342
Hi

I want values flash

I don't want to send it to the flash
0
 
LVL 11

Expert Comment

by:azarc3
ID: 24360461
one simple question; are you able to submit a for FROM Flash?
0
 
LVL 11

Expert Comment

by:azarc3
ID: 24360579
Have you done the Flash half of this yet? That's actually the hardest part.

Also, I understand that you don't want to send the form POST to Flash... but don't you want Flash to know if the submission was successful? Otherwise you'll be swallowing errors that you should want to know about.

Even if you choose not to evaluate the result of the form POST the code of the provided example will work. Just comment out or remove the context.Response.Write(); statements.
0
 

Author Comment

by:KaranGupta
ID: 24361095
Hi azarc3

I am a .net developer and I don't know anything about flash

The work in flash is done by a designer

she said

"I will send the following variables for submission:

name
email
subject
message

When a user will click on submit on the contact us page then following variables will sent to the page by POST method. "

Now the name of the page is Contact.aspx

How can I get the value from flash to .net.

0
 
LVL 11

Expert Comment

by:azarc3
ID: 24363032
In that case it's just like any other Web Form submission.

You can access the values using Request.Form.Item(fieldname) in the Page_Load or Page_PreRender events. Don't forget that this *"should" not* be considered a postback because it won't be sending the required field values.
0
 

Author Comment

by:KaranGupta
ID: 24363052
Hi

I have tried to print the value on page_load using Response.Write

but I didn't get any value

can I have any example of this type on internet
0
 
LVL 11

Accepted Solution

by:
azarc3 earned 500 total points
ID: 24363746
I'll do you one better; here's what you need. This code assumes you're using C# v9.0 (in v3.5 of the .NET Framework); if you're not you'll need to exchange the varios "var" keywords with the appropriate types.
// ************************

// Code for the receiving MailProcessor.aspx page:

// ************************
 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="MailProcessor.aspx.cs" Inherits="MailProcessor" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

        <div>

        

            <asp:Label ID="lblResults" runat="server" Text="... to be processed ..." />

        

        </div>

    </form>

</body>

</html>
 
 

// ************************

// Code for the receiving MailProcessor.aspx.cs page:

// ************************
 

using System;

using System.Net.Mail;

using System.Text;
 

public partial class MailProcessor : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // This is for while you're proving Flash can post to this page

        var sb = new StringBuilder();

        sb.Append("<p>");
 

        foreach (var formVariable in Request.Form.Keys)

        {

            sb.Append(string.Format("{0}: {1}<br />", formVariable.ToString(), Request.Form[formVariable.ToString()]));

        }
 

        sb.Append("</p>");

        lblResults.Text = sb.ToString();
 

        // This is for when you're ready to actually send emails

        SendEmail();

    }
 

    private void SendEmail()

    {

        // This is for when you're ready to process messages

        // Create instance of main mail message class.

        var intendedRecipient = "whomever@yourchoice.com";

        var SMTPServer = "your email server address";

        var SMTPServerPort = 25; //"whatever is required; if it isn't remove this variable from line 46

        

        using (var mailMessage = new MailMessage(Request.Form["email"].Trim(), intendedRecipient))

        {

            //Configure mail mesage
 

            // 1. Set the From address with user input

            mailMessage.Subject = Request.Form["subject"].Trim();

            mailMessage.Body = "From " + Environment.NewLine + Request.Form["name"].Trim() + Environment.NewLine + Environment.NewLine 

                                + "Message:" + Environment.NewLine + Request.Form["message"].Trim();
 

            // 2. Specify if this is Text or HTML

            mailMessage.IsBodyHtml = false;
 

            // 3. Create an instance of the SmtpClient class for sending the email

            var smtpClient = new SmtpClient(SMTPServer, SMTPServerPort);
 

            // 4. Use a Try/Catch block to trap sending errors; this is especially useful when looping through multiple sends

            try

            {

                smtpClient.Send(mailMessage);

                lblResults.Text += "<p>Message was sent</p>";

            }

            catch (SmtpException smtpEx)

            {

                lblResults.Text = smtpEx.Message;

            }

            catch (Exception ex)

            {

                lblResults.Text = ex.Message;

            }

        }

    }

}
 
 

// ************************

// Code for a page to send

//   from in order to test 

//   MailProcessor.aspx.cs:

// ************************
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

</head>

    <body>

        <form action="MailProcessor.aspx" method="post">

            <p>

                Name:<br />

                <input id="name" name="name" type="text" value="azarc3" />

            </p>

            

            <p>

                Email:<br />

                <input id="email" name="email" type="text" value="azarc3@somewhere.com" />

            </p>

            

            <p>

                Subject:<br />

                <input id="subject" name="subject" type="text" value="This is only a test" />

            </p>

            

            <p>

                Message:<br />

                <input id="message" name="message" type="text" value="blah blah blah" /><br />

            </p>

            

            <p>

                <input id="btnSubmit" type="submit" value="Send" />

            </p>

        </form>

    </body>

</html>

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now