3

I am trying to create an html file that open a web page in default browser and login, the page is in company intranet, and is .aspx strctured.

The page contain user, pwd field and a link to complete login procedure. the related source row is

<a id="lnkAccedi" href="javascript:__doPostBack('lnkAccedi','')" 
  style="background-color:Transparent;font-family:Arial;">Accedi...</a> 

and the simple code i've already tested is

<script language="JavaScript">
  window.open("intranet_web_page","_self");
</script>

where intranet_web_page is the URL of my login page. I tried to call the function defined in webpage source as "__doPostBack('lnkAccedi','');" in the script tag of my html file, but not work at all.

How can i do that?

Thanks in advance.

2 Answers 2

1

Actually I'm not an ASP user, but I believe that __doPostBack is a user defined function, you should defined it as a javascript function under the script tag.
And one point, I don't think that __doPostBack is need a parameter.

So if you want to create redirecting the user after authorized it without change the url, you can use jquery post method to post your data, then retrieve the server response under callback function to detect that user was authorized or not
I'll give you sample code, but actually I'm not tested it yet.
In HTML :

<form name="loginform" action="test.asp" method​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​="POST">
username : <input type="text"  name="username" placeholder="please put your username here." /><br>
password : <input type="password" name="password" placeholder="your password here" /><br/>
<a id="lnkAccedi" href="javascript:__doPostBack" style="background-color:Transparent;font-family:Arial;">Accedi...</a>
</form>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

On script:

function __doPostBack() {
    var usernamestr = document.loginform.username.value;
    var passwordstr = document.loginform.password.value;
    $.post("authorize.asp", { username: usernamestr , password: passwordstr },
       function(data) {
           if(data = "success") {       
               window.open('newwindow.asp','_self');
           } else {
               alert("Username or password was wrong");
           }
    });
}​

Last, suggestion : I think you don't have to control login process in the front end, because it's very dangerous, anyone can recreate your code and hack to your server, because it is client side. You should give the process control to the back end server.

Sign up to request clarification or add additional context in comments.

Comments

1

Do NOT do any kind of authentication with JavaScript!!!

Do your login authentication on the ASP code-behind and then pass a success condition where you can use response.write to open a new window. I do a similar thing opening a messenger window. On login success I have the following code:

Response.Write("<script> var win =window.open('chat.aspx','mywindow','width=700,height=450,left=800,top=10,location=1'); win.close();</script>") //closes the window if it is already open
Response.Write("<script>window.open('chat.aspx','mywindow','width=700,height=450,left=800,top=10,location=1')</script>") //open the window

Again, that is how I call the script from the code-behind. Hopefully that points you in the right direction!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.