Link to home
Start Free TrialLog in
Avatar of roknjohn
roknjohn

asked on

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

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?
Avatar of roknjohn
roknjohn

ASKER

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?
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  

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!  
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial