Solved

Delphi 8 ASP.NET Forms Authentication problem - "Server Application Unavailable "

Posted on 2004-07-30
5
372 Views
Last Modified: 2010-04-05
I am having difficulties using form authentication in my Delphi 8 ASP.NET application.

To test, I created a small project with two forms, WebForm1.aspx and Login.aspx in a new virtual directory under IIS on my Win 2KPro machine.  Both forms display fine using the "Run without debugging" option without authentication.

The problem arises when I add these lines to the web.config file:

  <authentication mode="Forms">
      <forms name="AuthTestCookie" loginUrl="login.aspx" protection="All" path="/" />
  </authentication>

  <authorization>
       <deny users="?" />
   </authorization>

With these additions, I often get a "Server Application Unavailble" error, but not always.  This is usually followed by a inetinfo.exe - Application Error popup (trying to read memory at 0x0000004).  

Sometimes, it will take me to the Login page, only to give the error after clicking the Login button.  The login form is simply a blank form with a button.  The event handler looks like this, for simplicity:

   procedure TLogin.Button1_Click(sender: System.Object; e: System.EventArgs);
   begin
     FormsAuthentication.RedirectFromLoginPage('TestUser',False);
   end;

WebForm1.aspx contains one line of text, "Hello World!!!".
  <form runat="server">Hello World!!!  </form>


Sometimes it works. Mostly, it doesn't.

I tested the application using Alt+RD, 'Run without Debugging' from Delphi 8. (The start page is set to WebForm1.aspx.)  
I've also tested directly from my browser -> http://localhost/AuthTest/WebForm1.aspx

I am using IIS, not Cassini.  

I can remove the "Deny Users" line from the web.config and both pages load ok.
IIS is set to allow aynonomous users.
I've tried   <deny users="*" />    as well.
I have run the command:
c:\winNT\microsoft.net\framework\v1.1.4322\aspnet_regiis.exe -i

Any ideas?
0
Comment
Question by:roknjohn
  • 3
5 Comments
 
LVL 1

Author Comment

by:roknjohn
ID: 11682379
This may be related...

 It doesn't look like my session objects are working either. On a form with one label (eName) and two buttons, I coded these events:

procedure TDefaultForm.Page_Load(sender: System.Object; e: System.EventArgs);
begin
  if Session['UserName']<>nil then
    eName.Text := Session['UserName'].ToString;
end;

procedure TDefaultForm.Button2_Click(sender: System.Object; e: System.EventArgs);
begin
  Session['UserName'] := 'John';
end;

procedure TDefaultForm.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
  Session['UserName'] := 'Paul';
end;

I thought that by clicking the buttons, the label would change to John or Paul.  
The label stays blank.  What gives?
0
 
LVL 1

Author Comment

by:roknjohn
ID: 11684572
I am still having this problem with authentication and session variables.  I suspect that the authentication problem is related to the more basic problem of the session variables not persisting.

Here what I've done:
I installed Update 2 from Borland.
I set my IE browser to 'Accept All Cookies'. (It was set to 'Low').
I created a new ASP.NET application, using all default names. (WebApplication1,etc.)
I added 3 labels and 2 buttons to WebForm1.
Here is the code that I added:

procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
begin
  Label1.Text := 'Session Id = '+Session.SessionID;
  if Session['MyVar']<>nil then
    Label2.Text := 'MyVar = '+Session['MyVar'].ToString
  else
    Label2.Text := 'MyVar is undefined.';
end;

procedure TWebForm1.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
  Session['MyVar'] := 'George Bush';
  Label3.Text := 'MyVar set to '+ Session['MyVar'].ToString;
end;

procedure TWebForm1.Button2_Click(sender: System.Object; e: System.EventArgs);
begin
  Session['MyVar'] := 'John Kerry';
  Label3.Text := 'MyVar set to '+ Session['MyVar'].ToString;
end;

Each time that the page is loaded, the SessionID stays the same, as expected, but the MyVar object is undefined.  When I click one of the buttons, Label3 correctly shows the new value, but Label2 always shows as undefined.

Here is the output:

First Display:
   Session Id = bjhiwo2fgvpsgcrxxsxqk245
   MyVar is undefined.
   Label  

After clicking Button1:
  Session Id = bjhiwo2fgvpsgcrxxsxqk245
  MyVar is undefined.
  MyVar set to George Bush  

After clicking Button2:
  Session Id = bjhiwo2fgvpsgcrxxsxqk245
  MyVar is undefined.
  MyVar set to John Kerry  

0
 
LVL 1

Author Comment

by:roknjohn
ID: 11685686
Problem solved.

I re-installed IIS (after removing it) then ran the aspnet_regiis.exe -i utility.  All works well now.  

Two days shot to heck!  
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13361151
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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