Solved

Asp.Net: writing a self-terminating web-application

Posted on 2004-08-04
12
600 Views
Last Modified: 2012-06-21
Hello experts,
I'm in need to write an Asp.Net web application (in VB.Net) as follows:
- it can be called only by http://www.xxx.com:<port>
  How can I ensure this?
- it writes something to a database (no question)
- it terminates itself
  How can I perform this?

If anyone knows a solution please supply appropriate [snippet] information.

   Thank you very much!

     HStrix
 
0
Comment
Question by:HStrix
12 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 11723760
Hi,
for creating a site to a secific port you have to open the IIS and create a new site and set the port to be different than the default 80 port. so when you call the www.xxx.com it will call the default site on your IIS, but if you type the www.xxx.com:yyyy where yyyy is the number of the port than your site will be called up

for the termination - what exactly do you want to perform ? because the site is active (doing something) when you call it, otherwise it is inactive and waintg for calls

Regards,
B..M
0
 

Author Comment

by:HStrix
ID: 11724141
Thanks mmarinow,
the application for the site exists as IIS web application.
It exists and 'waits' that is will be used (that is current plan).
In normal cases the web application gets activated selecting a URL.
Then you finish the application by (for instance) clicking the X in the top right corner of the Internet Explorer.
For my situation,
I want that the web application gets activated by a sending its URL from a program.
And then - if its function is done - it shall simulate the click on the X or anything else to close the Internet Explorer.
I don't know if this is possible.
Probably I need to write a web service.
But I'm unsure if I have to.
Perhaps I also think not in the right direction,
but the function is as I described.

  HStrix
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11724229
You can close the Internet Explorer window by putting the snippet  below at the point in your code where processing completes:

    RegisterStartupScript("close","<script Language=JavaScript>  window.close(); </script>

This will add the javascript to the bottom of the page, so that as the page completes loading, it closes itself.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11724262
Sorry, missed the closing quote and bracket. Should be:

    RegisterStartupScript("close","<script Language=JavaScript>  window.close(); </script>")

However, this will cause a message box "The page you are viewing is trying to close the window" and the user has to click on a button. Is this acceptable?

Another approach would be for the calling program to initiate the program by requesting the URL, waiting for the page to load, scanning the HTML for a particular success or failure message, then ending the session. That's easy enough to do in a program. I've done it before in VB6.
0
 

Author Comment

by:HStrix
ID: 11724860
Thanks crescendo,
your second comment sounds very good.
Can you supply this VB6 snippet?
0
 

Author Comment

by:HStrix
ID: 11725020
==> "However, this will cause a message box "The page you are viewing is trying to close the window" and the user has to click on a button.
          Is this acceptable?"

I'ld like to suppress/prevent such a message, because it shall run without any user inter action.



0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 17

Expert Comment

by:AerosSaga
ID: 11725254
0
 
LVL 9

Accepted Solution

by:
crescendo earned 500 total points
ID: 11725327
Here's the VB6 code. You need to install MSXML2 (get it from MS) for it work. Basically the code below sends a request with some querystring parameters to a web page, gets the returned HTML and looks for some text inside <P> </P> tags. I'm sure you can modify it to suit your needs.

Public Function Register() As Boolean
    Dim httpReq As MSXML2.XMLHTTP40
    Dim sURL As String
    Dim sStatus As String
    Dim lStart As Long
   
    On Error GoTo RegErr
   
    Register = False
    sErrorString = ""
    sComputer = ComputerName
   
    Set httpReq = New MSXML2.XMLHTTP40
   
    sURL = "http://www.yourdomain.com/somepage.aspx" & _
           "?ProductKey=" & sProductKey & _
           "&Computer=" & sComputer

    httpReq.Open "GET", sURL, False
    httpReq.send
   
    lStart = 1
   
    ' See if it was successful
   
    sStatus = GetReplyString(httpReq.responseText, lStart)
   
    If sStatus = "SUCCESS" Then
        sLicenseString = GetReplyString(httpReq.responseText, lStart)
    ElseIf sStatus = "ERROR" Then
        sStatus = GetReplyString(httpReq.responseText, lStart)
        Err.Raise vbObjectError + 1024, "Registration", sStatus
    Else
        Err.Raise vbObjectError + 1024, "Registration", "Reason unknown"
    End If
   
    Register = True
   
RegExit:
    Set httpReq = Nothing
    Exit Function
RegErr:
    sErrorString = Err.Description
    Resume RegExit
End Function

Private Function GetReplyString(sResponse As String, lStart As Long) As String
    Dim lPosStart As Long
    Dim lPosEnd As Long
   
    lPosStart = InStr(lStart, sResponse, "<p>", vbTextCompare)
   
    If lPosStart = 0 Then
        GetReplyString = ""
        lStart = Len(sResponse)
        Exit Function
    End If
   
    lPosEnd = InStr(lPosStart + 3, sResponse, "</p>", vbTextCompare)
   
    If lPosEnd = 0 Then
        GetReplyString = ""
        lStart = Len(sResponse)
        Exit Function
    End If
   
    GetReplyString = Mid(sResponse, lPosStart + 3, lPosEnd - lPosStart - 3)
   
    lStart = lPosEnd + 4
   
End Function
0
 

Author Comment

by:HStrix
ID: 11725931
Thank you very much crescendo,
another idea could be (similar as you suggested):
   RegisterStartupScript("close", "<script Language=JavaScript>  history.back(); </script>")
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11726209
Yes, that would take you to the previous page in the browser, if one existed. But it wouldn't close the window.
0
 

Author Comment

by:HStrix
ID: 11743435
Hello crescendo,
now my checks are finished.
Based on your code I modified it and got it to work solving my problem.
I needed to replace
    Set httpReq = New MSXML2.XMLHTTP40
by
   Set httpReq = New MSXML2.ServerXMLHTTP30
In addition, I stripped the line of the asp.net application containing
my indicating field "asp_chk" using InStr commands (simular as you've done)
   lPosStart  = InStr(sResponse, "<textarea name=""asp_chk""")
   tmpString = Mid(sResponse, lPosStart)
and
   lPosEnd = InStr(tmpString, "</textarea>")
   strTagLine = Mid(tmpString, 1, lPosEnd + Len("</textarea>"))
Then I used the following function to detect the value:
---
Public Function readXmlValue(actXMLString As String) As String
Dim domDoc             As MSXML2.DOMDocument
Dim strTagValue       As String
Dim strXmlString       As String
    readXmlValue= ""    
    Set domDoc = CreateObject("Microsoft.XMLDOM")
    domDoc.async = False
    strXmlString = "<?xml version=""1.0"" ?><dummy>" & actXMLString & "</dummy>"
    domDoc.loadXML (strXmlString)
    strTagValue = domDoc.Text    
    readXmlValue = strTagValue      
End Function
---
In the Page_Load event of the asp.net application I inserted:
---
        Me.asp_chk.Text = "before"
        Call write2file("before")                   ' this routine writes this line to a local text file
        Me.asp_chk.Text = "close me!"        ' that is my value indicating the close
        Call write2file("after")
---
Again, thank you very much for your help.
 
   HStrix

0
 
LVL 9

Expert Comment

by:crescendo
ID: 11743712
Well done for getting it working, and thanks for sharing the finished product, others will find that useful in the future.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

14 Experts available now in Live!

Get 1:1 Help Now