Solved

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

Posted on 2004-07-30
5
362 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now