Tech Off Thread

7 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

How to bounce a unauthenticated user in c#

Back to Forum: Tech Off
  • User profile image
    josh_harris

    Hi all

    I am in the middle of converting some of my webapps to c#, and am wondering how to bounce a user that is not authenticated, ie do this
            If Not My.User.IsAuthenticated() Then
                Response.Redirect("default.aspx")
            End If

    but in c#

    any ideas?

    Thanks

  • User profile image
    jsampsonPC

    if(!User.Identity.IsAuthenticated()){
        Response.Redirect("default.aspx");
    }

    Just guessing there Smiley

  • User profile image
    borosen

    josh_harris wrote:
    Hi all

    I am in the middle of converting some of my webapps to c#, and am wondering how to bounce a user that is not authenticated, ie do this
            If Not My.User.IsAuthenticated() Then
                Response.Redirect("default.aspx")
            End If

    but in c#

    any ideas?

    Thanks


    Going out on a limb here, not knowing anything about your setup.

    Have you considered letting the system taking care of that for you?

    Using the authentication and authorization elements in web.config, that is.

  • User profile image
    bhamdevelop​er

    if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Resonse.Redirect("default.aspx");
    }


    Of course you could put a

    using system.Web;

    at the top to reduce the amount of stuff in the parenthesis

  • User profile image
    josh_harris

    bhamdeveloper wrote:
    if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Resonse.Redirect("default.aspx");
    }


    Of course you could put a

    using system.Web;

    at the top to reduce the amount of stuff in the parenthesis


    Thanks, That helped alot

  • User profile image
    jsampsonPC

    No fair! That's the exact same answer I gave....and I was the first to answer you! Tongue Out

    josh_harris wrote:
    
    bhamdeveloper wrote:if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Resonse.Redirect("default.aspx");
    }


    Of course you could put a

    using system.Web;

    at the top to reduce the amount of stuff in the parenthesis


    Thanks, That helped alot

  • User profile image
    josh_harris

    Woops, that teaches me for going straight to the last reply.. Tongue Out

    jsampsonPC wrote:
    No fair! That's the exact same answer I gave....and I was the first to answer you! Tongue Out

    josh_harris wrote:
    bhamdeveloper wrote:if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Resonse.Redirect("default.aspx");
    }


    Of course you could put a

    using system.Web;

    at the top to reduce the amount of stuff in the parenthesis


    Thanks, That helped alot

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.