p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.x and 2.0 Application Design (http://p2p.wrox.com/forumdisplay.php?f=67)
-   -   access C#.Net page as action of calssic ASP page (http://p2p.wrox.com/showthread.php?t=62889)

mansharma_s October 14th, 2007 10:22 PM

access C#.Net page as action of calssic ASP page

I am trying to access a .Net page form as action on a Classic ASP page (both are on different domains). The sequence of the page execution is as under:

1. Classic ASP Page that accepts User Name, Password and a token number. This page is submitting twice. On first submit the action of this page is itself. It Encrypts the values and place them in hidden controls and again submits it; this time the action of this page is a C# .Net Page.
2. C#.Net page Decrypts the values and verifies the User. If user is a valid user it generates a form in it (using JavaScript) and action of this generated page is again a classic ASP page.

When I open a new browser execute the classic ASP Page. The classic ASP page submitted twice (as planed to do so). Second submit action is C#.Net Page and I get the error on C#.Net page.

I am getting this Error on C#.Net page
   "Object reference not set to an instance of an object. "

The magic begins here. When I click on back Button of browser the classic ASP page gets submitted again (because it has the true condition for second submit) and this time it works fine and I got the expected results. After that If I continue with the same browser window for other user verification; it works fine through out. But again if I use a new browser window it gives the same error first time.

I have checked all controls names, values and form generation condtions; but not getting why it is happening. Please help me out.

Thanks & Regards

planoie October 15th, 2007 08:20 AM

What are the details of the code that is crashing? Is the .NET code using session values that aren't there on the first hit?

It sounds like you are creating a remote authentication type system. Instead of making several round trips between server and client, perhaps you could simplify this process with a single call to the target server doing the authentication. Seeing as you are in ASP, you could use the XmlHttpRequest object that should be available on your web server to make the request to the other server instead of using several auto posting forms.


mansharma_s October 17th, 2007 10:53 AM

Thanks Peter,

sorry for late reply. No I am not using session values, I am using textbox ( the input tag ). and here is the error as it appear on the screen:

Server Error in '/' Application.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 21:
Line 22:
Line 23: un = Request.Form["username"].ToString();
Line 24: ps = Request.Form["password"].ToString();
Line 25: tkn = Request.Form["ltoken"].ToString();

Source File: Authenticate.aspx.cs Line: 23

First time I get this error. I click on back button; the ASP page gets submitted autometically and the C# page loaded second time and I get no error this time.


planoie October 18th, 2007 01:11 PM

That is strange indeed. I can't imagine why it's behaving the way you describe.

Perhaps you could use a tool like Fiddler to debug the HTTP activity and see what is actually getting posted to the .NET page each time.


mansharma_s October 23rd, 2007 01:03 PM

Thanks Peter

I tried everthing I can including debugging but no luck. It works fine with QueryStrings so I Implemented it with QueryStrings for right now. Hope I get some solution in near future. :)

Thanks and Regards

mujahidkhaleel January 3rd, 2008 08:50 AM

You cannot do POST to a ASP.NET page from ASP. The ASP.NET page will not find the server side controls and thus not allow POST values.

Alternate is to have the form in ASPX page and then redirect the successfully validated user back to ASP page.

Mujahid Khaleel
Web designing, development, E-commerce applications.

planoie January 7th, 2008 10:58 AM


quote:Originally posted by mujahidkhaleel
 You cannot do POST to a ASP.NET page from ASP. The ASP.NET page will not find the server side controls and thus not allow POST values.

This is not true. You most certainly can post any html form regardless of where it comes from to an ASP.NET page. Yes, the ASP.NET page will not find control instance values from the posted form, or at least they won't be valid if they are there, but you can access the raw form as this use is demonstrating. You'll need to know the form fields (such as the hidden fields in this case) and you can get their values from the forms collection just like we would in classic ASP.

What the OP is trying to do should work, but isn't.


All times are GMT -4. The time now is 02:15 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.