locked
cheack for User.Identity.IsAuthenticated in Java script RRS feed

  • Question

  • User530380349 posted

     Hi everyone,

    Im triyng to cheack if my user is logined in or not? and if they are not the onclick sould direct them to the "acount.aspx" page  and if they are it should continiue doing what it should be doing.

    <input type="image" onclick="CheckUser()" src="http://www.ecovidadesign.co.uk/addtocart.jpg" style="border:0" name="submit" alt="" />

     

    script language="javascript">
            function CheckUser()
            {
              Any Idea what goes here?
            }
        </script> 

     

    the code for the Paypal button is:

    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
    <input type="hidden" name="cmd" value="_s-xclick" />
    <input type="hidden" name="hosted_button_id" value="2966249" />
    <input type="image" src="http://www.ecovidadesign.co.uk/addtocart.jpg" style="border:0" name="submit" alt="" />
    <img alt="" style="border:0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1" />
    </form>

    Friday, February 20, 2009 3:01 AM

Answers

  • User-1171043462 posted

    OK So a trick
    Take 2 divs say dvPayPal and dvDummy add runat =server to both
    in dvPayPal add the whole html for the pay pal that you have
    in dvDummy add a imagebutton with paypal image
     
    now on page load when user comes check
     
    if (user authenticayion == true)
    {
    dvDummy.visible=false
    dvPayPal .visible=true
    }
    else
    {
    dvDummy.visible=true
    dvPayPal .visible=false
    }

    So when user clicks on dummy button he will be redirected to login page and ehen he logs is the dvDummy wil be hidden so when he clicks he is taken to paypal page

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 24, 2009 4:00 AM

All replies

  • User377791177 posted

    Sarah,

    Do u specifically want to do the login validation on the client side only? generally these things are achieved through authentication mechanisms (formsauthentication, windows authentication etc.) , for example settingup of asp.net membership and then using login controls shall achieve the objective.

    Friday, February 20, 2009 5:15 AM
  • User530380349 posted

     Yes please explain more.

    The reason I thought it could not be done using ASP.NET

    http://forums.asp.net/p/1385545/2953603.aspx#2953603

    Thanks

     

    Friday, February 20, 2009 5:22 AM
  • User377791177 posted

    The quick n best solution is to use ASP.NET membership feature, it creates some database tables (which asp.net does for you by using a small utility aspnet_regsql) and then modifying the web.config to include the membership elements.

    After these two things are done, you can use asp.net login controls to validate the user.  here is a nice article on how to use asp.net membership. also a web.config sample from one of my projects

    <roleManager enabled="true">
          <providers>
            <clear />
            <add name="AspNetSqlRoleProvider" connectionStringName="DBAuth" applicationName="AnywhereSurvey" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          </providers>
        </roleManager>
        <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
          <providers>
            <clear />
            <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DBAuth" applicationName="AnywhereSurvey" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" />
          </providers>
        </membership>

    Friday, February 20, 2009 5:31 AM
  • User-1763611275 posted

    Hi

    check this example to check username availablity with ajax

    http://yasserzaid.wordpress.com/2009/02/05/check-username-availablity/

    Good Luck

    Saturday, February 21, 2009 9:14 AM
  • User530380349 posted

    Thanks I dont want to check if user name is avaliable. I need to see if the user is login or not if they are let them direct to the paypal shopping cart and if they are not they should be directed to the login page.

    Thanks

    Sunday, February 22, 2009 1:06 PM
  • User-1171043462 posted

    As David Qian said you will need to use AJAX and make a asunchronous call to ther server

    you will have to use JavaScript and XML Http and make a call to the server. The server will check whether user is authenticated if yes return true else false

    based on that you can redirect the user to the page you want using window.location property of javascript

    To make call to server using xmlhttp refer my article

    http://www.aspsnippets.com/post/2009/02/01/AJAX-Calls-Using-JavaScript-And-XMLHTTP.aspx

    Here it sends the server time instead you will have to check on page load

    if (Page.User.Identity.IsAuthenticated)

    {

    Response.Write("true");

    Response.End();

    }

    else

    {

    Response.Write("false");

    Response.End();

    }

     

    And whwn client side javascript will receive it you can check

    if (xmlhttp.responseText == "true")

    {

    window.location="SomePage.aspx";

    }

    else

    {

    window.location="Login.aspx";

    }

    Sunday, February 22, 2009 2:30 PM
  • User-299048901 posted

    Try this

    <input id="userAuth" type="hidden" value="<%= My.Request.IsAuthenticated %>" />

    if (document.getElementById("userAuth").value == "True") { [do this] } else { [do that] }

    Sunday, February 22, 2009 2:50 PM
  • User401360897 posted

     i think use a Hiddden Field at server side set this in Page Load by User.Identity.IsAuthenticated

     

    Monday, February 23, 2009 4:34 AM
  • User-1171043462 posted

    OK So a trick
    Take 2 divs say dvPayPal and dvDummy add runat =server to both
    in dvPayPal add the whole html for the pay pal that you have
    in dvDummy add a imagebutton with paypal image
     
    now on page load when user comes check
     
    if (user authenticayion == true)
    {
    dvDummy.visible=false
    dvPayPal .visible=true
    }
    else
    {
    dvDummy.visible=true
    dvPayPal .visible=false
    }

    So when user clicks on dummy button he will be redirected to login page and ehen he logs is the dvDummy wil be hidden so when he clicks he is taken to paypal page

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 24, 2009 4:00 AM
  • User530380349 posted

     Yes and guys dont forget to add the onclick="Button1_Click" on the button that is in the dummydiv

    protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsPostBack == true && Page.User.Identity.IsAuthenticated == false)
            {
                Server.Transfer("Login.aspx");
            }

        }

    Tuesday, February 24, 2009 4:05 AM
  • User-1171043462 posted

     Yes and guys dont forget to add the onclick="Button1_Click" on the button that is in the dummydiv

    protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsPostBack == true && Page.User.Identity.IsAuthenticated == false)
            {
                Server.Transfer("Login.aspx");
            }

        }

    Yes correct I forgot to paste it. Plz mark your post asn answer too

    Tuesday, February 24, 2009 4:09 AM