Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

flash and .net

Posted on 2009-05-11
14
Medium Priority
?
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 11

Expert Comment

by:Kelvin McDaniel
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:Kelvin McDaniel
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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:Kelvin McDaniel
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:Kelvin McDaniel
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
 

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:Kelvin McDaniel
ID: 24360461
one simple question; are you able to submit a for FROM Flash?
0
 
LVL 11

Expert Comment

by:Kelvin McDaniel
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:Kelvin McDaniel
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:
Kelvin McDaniel earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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