Question

I am using ASP.NET membership and on registration page trying to login without a login control.

When user clicks on the register button, the control goes to redirect.aspx page. But in that page, while I am trying to redirect to the members homepage its throwing the following error.

ERROR -

Unable to evaluate expression because the code is optimized or a native frame
is on top of the call stack.

Web.config -

<authentication mode="Forms">
    <forms name=".SSOAuth" loginUrl="login.aspx" defaultUrl="Redirect.aspx"
           protection="Validation" timeout="30000"/>
</authentication>

RegistrationPage code -

protected void btnRegister_Click(object sender, EventArgs e)
{
    MembershipUser userMemb = Membership.CreateUser(
                           txtemail.Text.Replace("'", "''").ToString(),
                           txtPassword.Text.Replace("'", "''").ToString(),
                           txtemail.Text.ToString());

    Roles.AddUserToRole(txtemail.Text.ToString(), "Member");
    FormsAuthentication.RedirectFromLoginPage(txtemail.Text.Trim(), false);
}

Redirect.aspx.cs code -

try
{
    if (User.IsInRole("Member"))
    {
        string UserName = User.Identity.Name;                        
        Response.Redirect("~/Member/MembeHome.aspx");
    }
}
catch(Exception ex) {}
Was it helpful?

Solution

Read this document (issue and solution) ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

Use Response.Redirect(url,false)

Response.Redirect("~/Member/MembeHome.aspx",false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top