views:

501

answers:

3

I need to pass some data from a classic ASP application to my ASP.NET app using the POST method (can't use GET sorry) in a form.

This doesn't seem to work if my action is the target aspx page but my ASP.NET app is using forms authentication, because it looks like somewhere in the pipeline my data is lost, given that the Request.Form collection is null in the Page_Load method of my login page.

If I disable forms authentication, the target page receives the posted data without a problem.

Do you know how can I work-around this problem? When or where could I obtain this data?

Thanks in advance!

A: 

The 2 possible way to transfer data between asp to aspx is

  1. using Session, Via SQL DB (Ref. http://msdn.microsoft.com/en-us/library/aa479313.aspx

  2. Using QueryString in a intermediate ASP page as below.

Your 1st ASP page : sample.asp

<% language="VBScript"%>
<html>
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" action="process.asp" method="post">
    <div>
        &nbsp;<input name="Text1" id="Text1" type="text" />
        <input id="Submit2" type="submit" value="submit" /></div>
    </form>
</body>
</html>

Your Intermediate page : process.asp

<%@ language="vbscript"%>
<html>
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form id="form2">
    <%response.Write(Request.Form("Text1"))
     %>
    <%response.Redirect("default3.aspx?icontent=" & Request.Form("Text1"))  %>
    </form>
</body>
</html>

Your ASPX code page : Default.aspx

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Request.QueryString["icontent"].ToString());
    }

}
solairaja
I'm aware of this, I was wondering if there's no way of use POST (hence my no GET comment) to pass data around, given that I can't change the way the ASP app is coded (and is data that doesn't need to be seen in the query string). DB is definitely an overkill for a simple problem. And even the (third?) POST option work, unless I implement forms authentication, then my data loses its way.
murki
but this is how we can share data between asp and aspx in most of the production scripts too as i hav worked. but everything is based on the requirement, if it really need then we have to look for the workaround, but i wonder there wont be any available as of now to my little knowldege. :)
solairaja
A: 

Can you just unprotect the single page that's the target of the POST?

In your web.config:

<configuration>
  <location path="MyPostHandlingPage.aspx">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
</configuration>
Greg
Well I think this defies the purpose of using the authentication in the first place, at least in my case.
murki
Sorry about that. I figured protection for the whole site except the integration point would be good enough.
Greg
+1  A: 

A possibility might be to transfer the posted headers into a session object you maintain in your ASPX side that would then be killed once its purpose is complete.

void Session_Start(object sender, EventArgs e) 
{
    // Code that runs when a new session is started
    SortedList sList = new SortedList();
    foreach (string key in HttpContext.Current.Request.Form.Keys)
    {
        sList.Add(key, HttpContext.Current.Request.Form[key]);
    }
    Session.Add("myList", sList);

}
Joel Etherton
Sounds like a plausible workaround, I had to remove "forms authentication" from my project and use my own implementation, but I'll keep an eye on the post to see if your answer is the best. Thanks!
murki