?
Solved

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

Posted on 2004-08-04
12
Medium Priority
?
648 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
[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
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
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!

 
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
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11725254
0
 
LVL 9

Accepted Solution

by:
crescendo earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

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