Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ISAPI app with ASP.NET connecting via TCP to a server

Posted on 2004-11-01
8
Medium Priority
?
189 Views
Last Modified: 2010-04-05
Hi! I need som help with a D8 solution. I just bought D8, and there is alot of differenses between D5 and D8.

I need a Web solution on an IIS connecting to a server and recieve data and present it on the web.

Meaning: A login check via the web server, from the webserver to the internal server and then present the result on the web.
I have never used .NET so if it is possible to help me with a start up project, this would be great.

More points will be given on delivery of a project.

I have a D5 solution for this today, but I would like to have a .NET solution, possibly with some type of cryptation at least for the password if possible.

/Mersan  
0
Comment
Question by:mersan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 22

Assisted Solution

by:Mohammed Nasman
Mohammed Nasman earned 300 total points
ID: 12461480
Hello

   Webbroker doesn't include with Delphi 8, so you can't develop ISAPI with Delphi 8, the way you should go with is Asp.net application

But I think if you go with Web Services the work you want to done will be more easier, and you can use windows and web application as clients to connect to your web service

here's some articles to help you to build that for Delphi 8 and Delphi 6/7

http://delphi.about.com/od/aspnet/
http://www.thedelphimagazine.com/samples/1273/1273.htm
http://bdn.borland.com/delphi/webtech/0,1418,10005,00.html
http://www-106.ibm.com/developerworks/db2/library/techarticle/dm-0403swart/index.html?ca=dnp-312
http://www-106.ibm.com/developerworks/db2/zones/borland/


HTH

Regards,
Mohammed
0
 

Author Comment

by:mersan
ID: 12461603
I will have a look, but I have some time presure, so if you can help me with some code specific for this problem, it will help me alot.

/Mersan
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12461934
could you explain more for what would you like to accomplish
0
Technology Partners: 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!

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12462938
It's been a while since I worked with D8 again on a web-application with logon functionality, but it's not as difficult as you think. When you create a new ASP.NET project with Delphi 8, and save it, there will be a file called "web.config" in your project folder. As you could have guessed, this is where you set up the configuration for your project when it is running! ASP.NET will read this file and set up default values, and -if specified- it will check if the user is logged on or not. Best thing to do is Google for it since I myself was a bit limited by my web provider in the ways that I could use to log on. Still, http://www.workshop-alex.org/Avalon/ is a very easy example of what I've done for a hobby page of mine. Too bad I'd hidden the logoff button a bit. (On the "Merchant" page at the bottom.) It's a crappy page, btw... I started with it when I first bought Delphi 8 but never found time to finish it.

The web.config file for that page of mine looks like this: (Without the comments)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="false"  defaultLanguage="c#">
    </compilation>
    <customErrors mode="Off" />
    <authentication mode="Forms">
      <forms name=".Merchants" loginUrl="login.aspx" protection="All" timeout="60" path="/" slidingExpiration="true">
      </forms>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20"/>
    <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
  </system.web>
</configuration>

The important parts are the authentication and authorization parts. In the authorization I deny access to everyone. Thus, everyone has to authenticate first. And for authentication they have to visit the logon page, which responds on the buttonclick. The code behind this click is simple. I open a database connection, search for username and password and if ffound, I call:
  System.Web.Security.FormsAuthentication.RedirectFromLoginPage(Recs.Fields['FirstName'].Value.ToString, CheckBoxRemember.Checked);
and afterwards, the user is authenticated, thus logged in.
The fun thing is that ASP.NET will maintain information if the user is logged on or not and will even require the user to log on again once his logon info has expired.

However, I used a HTTP:// link to the logon page, while a HTTPS:// would be more secure. Then again, this is a limitation of my webserver which doesn't (easily) support secure connections...
0
 

Author Comment

by:mersan
ID: 12463279
Hi Alex, this sounds good, the only differense is that I want to have a socket connection between the web server and an application that will return values some thing like this.

Web page (login) -> web server -> win application

The win applicetion will check with a server/database if the login is correct. and send the result to the web client.

Web page (login) <- web server <- win application

I will use an IIS-server so the secure should not be a problem I think.

What is the best way to continue from here? Can you deliver a sample project? I will start an ASP.NET project and we´ll se where i get stuck.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 1200 total points
ID: 12463572
For a sample app I would first have to install D8 again, so that's a no. Sorry...
If you need to connect to a remote server for authentication then you can easily do this from the logon form, though. What I did was:

unit Login;

interface

uses
  System.Collections, System.ComponentModel, System.Data, System.Drawing, System.Web, System.Web.SessionState, System.Web.Security, System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls, ADODB, untDatabase;

type
  TWebFormLogin = class(System.Web.UI.Page)
  {$REGION 'Designer Managed Code'}
  strict private
    procedure InitializeComponent;
    procedure ButtonSubmit_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict private
    procedure Page_Load(sender: System.Object; e: System.EventArgs);
  strict protected
    TextBoxUsername: System.Web.UI.WebControls.TextBox;
    TextBoxPassword: System.Web.UI.WebControls.TextBox;
    ButtonSubmit: System.Web.UI.WebControls.Button;
    CheckBoxRemember: System.Web.UI.WebControls.CheckBox;
    LiteralInfo: System.Web.UI.WebControls.Literal;
    RequiredFieldValidator1: System.Web.UI.WebControls.RequiredFieldValidator;
    procedure OnInit(e: EventArgs); override;
  end;

implementation

{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWebFormLogin.InitializeComponent;
begin
  Include(Self.ButtonSubmit.Click, Self.ButtonSubmit_Click);
  Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}

procedure TWebFormLogin.Page_Load(sender: System.Object; e: System.EventArgs);
begin
  if (TextBoxUsername.Text.Length = 0) then TextBoxUsername.Text := 'Guest';
  if (TextBoxPassword.Text.Length = 0) then TextBoxPassword.Text := 'guest';
  LiteralInfo.Text := 'For guests, use "Guest" as username and "guest" as password.';
end;

procedure TWebFormLogin.OnInit(e: EventArgs);
begin
  InitializeComponent;
  inherited OnInit(e);
end;

procedure TWebFormLogin.ButtonSubmit_Click(sender: System.Object; e: System.EventArgs);
var
  Conn: Connection;
  Recs: Recordset;
begin
  Conn := NewConnection(Context.Request.PhysicalApplicationPath);
  Recs := NewRecordset(Conn, 'select * from users');
  Recs.Filter := 'Username = ''' + TextBoxUsername.Text.Trim.ToUpper + '''';
  if (Recs.RecordCount = 0) then begin
    LiteralInfo.Text := 'Username "' + TextBoxUsername.Text.Trim + '" not found. Please try again.';
  end else if Recs.Fields['Password'].Value.ToString.Equals(TextBoxPassword.Text) then begin
    System.Web.Security.FormsAuthentication.RedirectFromLoginPage(Recs.Fields['FirstName'].Value.ToString, CheckBoxRemember.Checked);
  end else begin
    LiteralInfo.Text := 'Invalid password. Please try again.';
  end;
  Recs.Close;
  Conn.Close;
end;

end.

Page_Load just sets up default login information in the editboxes but you could retrieve them from a cookie or from some other source. All other methods except ButtonSubmit_Click and Page_Load were created by D8, btw. And in ButtonSubmit_Click I know the user clicked on Logon so I check his credentials there.
At that point, you could connect to another server like I connected to a database. The NewConnection() and NewRecordset() are just two simple functions I created to connect to an Access database with the user information.
However, you do have to keep in mind that your web application must have access rights to connect to the second server, else IIS will just block it. (And this too is a limitation of my own webserver, since it doesn't allow webapps to connect to other locations on the Internet.)

Basically, you get:
Client logs in [username, password]
Server 1 forwards [username, password]
Server 2 validates [username, password]

And if the data is valid, we continue with:
Server 2 validated ok [username]
Server 1 Authenticates [username]
Client is logged on.

If invalid, we get this:
Server 2 reports error
Server 1 returns error
Client is NOT logged in and has to try again.

Notice that if the user fails, the form is just re-used but LiteralInfo gets some value that is displayed to the user. It could be made even more complicated but hey, it was my first test 5 months ago and I've forgotten most about it again since I returned to Delphi 5 at work. (And Delphi 7 at home.) I like Delphi 8 yet am not too comfortable about it yet.
0
 

Author Comment

by:mersan
ID: 12463774
I will test this first thing tomorrow.
0
 

Author Comment

by:mersan
ID: 12581729
I tested it, but I cannot make it work. I will not communicate with my webserver.

Never mind, I will try to make it work.

/Mersan
0

Featured Post

Industry Leaders: 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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