Response redirect does not appear to execute

Hi experts,

I'm writing an asp.net applicaion using vb.net and have configured the membership table with the login control.  When the user logs in I want to to redirect them to a Browser.aspx page so I've put this code in the 'Protected Sub Login1_LoggedIn' event. However when I debug this the line 'Response.Redirect("Browser.aspx")' executes but does not go to that page, it just executes and returns to the login page.  Any ideas what I'm doing wrong?

The code for the login fuction is as follows:


Imports System.Data.SqlClient

Partial Class SignIn
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
        Session.Item("customerConfigFilePath") = Server.MapPath("~") & "\XML files\CustomerFile.xml"
        Session.Item("customerProjectsFile") = Server.MapPath("~") & "\XML files\Projects.xml"

        'Response.Redirect("Browser.aspx")
        HttpContext.Current.Response.Redirect("Browser.aspx", False)

    End Sub
End Class
MOSSPOINTAsked:
Who is Participating?
 
buraksaricaConnect With a Mentor Commented:
try DestinationPageURL property of Login control instead of redirecting user with response.redirect(), you can also set session variables on Logged-in event, just remove redirect and set DestinationPageURL.
0
 
Carl TawnSystems and Integration DeveloperCommented:
You need to set the second parameter to false, otherwise the standard login stuff will take over and stop your redirect working.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Let me try that again! You need to set the second parameter to TRUE, rather than FALSE
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Kumaraswamy RCommented:

this.Response.Redirect("Browser.aspx", true);


The second argument is endResponse.  
When true, it, well, ends the request.  
It does so by throwing a ThreadAbortException after the redirect is sent.




0
 
MOSSPOINTAuthor Commented:
Chaps,

Thanks for the responses unfortunately none work.

I tried,  HttpContext.Current.Response.Redirect("Browser.aspx", True), does the same thing, i.e. the line executes, takes me back to the login page with the username/password blank.

I tried, this.response.redirect("Browser.aspx") but it didn't understand the 'this' part?

I commented out any re-direct lines and set the destination URL to ~Browser.aspx and that didn't work either.

Any more ideas?

  Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
        Session.Item("customerConfigFilePath") = Server.MapPath("~") & "\XML files\CustomerFile.xml"
        Session.Item("customerProjectsFile") = Server.MapPath("~") & "\XML files\Projects.xml"

        'Response.Redirect("Browser.aspx")
        HttpContext.Current.Response.Redirect("Browser.aspx", True)
        'this.response.redirect("Browser.aspx")
0
 
buraksaricaCommented:
Can you share the web.config access definitions part? You may misspelled or misconfigured something? sharing all of your web.config with removing sensitive info is better.
0
 
Carl TawnSystems and Integration DeveloperCommented:
And also how your login control fits into the structure of your page. All of the solutions provided should have worked, so there must be something else in your page that is interferring.
0
 
Alfred A.Commented:
Try the following:

Response.Redirect("Browser.aspx", False)
HttpContext.Current.ApplicationInstance.CompleteRequest()
Return

Also, try to put a try/catch in there to check why it is not redirecting.  If the second parameter is true, you might get a ThreadAbortException.

Try
     Response.Redirect("Browser.aspx", False)
Catch ex As Exception
     Dim ErrStr as String = ex.Message
End Try

Check the following links.  This might help.

http://www.c6software.com/articles/ThreadAbortException.aspx

http://stackoverflow.com/questions/2777105/response-redirect-causes-system-threading-threadabortexception

http://support.microsoft.com/kb/312629

I hope this helps.
0
 
MOSSPOINTAuthor Commented:
OK, the try raises the following exception?

System.Threading.ThreadAbortException      {Property evaluation failed.}
0
 
buraksaricaCommented:
Please share your web config in order to let us understand your authentication details. How you secure the pages through forms auth.
0
 
Alfred A.Connect With a Mentor Commented:
Try the following as well.  I tested this with a test project just to be sure and I am able to redirect to a page inside a Login event.  Also, the Response.Redirect("Browser.aspx",True) works well and this is what I always use.  I just ignore the ThreadAbortException.  Also, the two lines in my suggested code below is actually one line in Response.Redirect where second parameter is set to true (endReponse).  I just don't know why it is not working in your project but you can try what I suggested below.

Also, are you using forms authentication?  If you are, this might be interferring with the page redirection.  As others said, please provide us a code snippet of your web.config minus sensitive parts so we can further analyse what is wrong with your page redirection.
Response.Redirect("Browser.aspx", False)
Response.End()

''OR, Try the following (the one above should be enough):

Try
     Response.Redirect("Browser.aspx", False)
Catch ex As Exception
     Dim ErrStr as String = ex.Message
End Try

Response.End()

Open in new window

0
 
MOSSPOINTAuthor Commented:
Hi Experts,

Here's my web.config file, not sure what it means but here it is anyway.

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
      <configSections>
            <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? ">
                  <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=????????????????>
                        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? " requirePermission="false" allowDefinition="MachineToApplication"/>
                        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? ">
                              <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? " requirePermission="false" allowDefinition="Everywhere"/>
                              <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? " requirePermission="false" allowDefinition="MachineToApplication"/>
                              <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? " requirePermission="false" allowDefinition="MachineToApplication"/>
                              <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? " requirePermission="false" allowDefinition="MachineToApplication"/>
                        </sectionGroup>
                  </sectionGroup>
            </sectionGroup>
      </configSections>
      <appSettings>
      </appSettings>
      <connectionStrings>
            <remove name="LocalSqlServer"/>
            <add name="LocalSqlServer" connectionString="Data Source=s02.ServiceProvider.com;Initial Catalog=DB_4996_company;User ID=DB_4996_company_user;Password=?????????;Integrated Security=False;"/>
      </connectionStrings>
      <!--connectionStrings>
            <add name="EMVConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\testing.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
      </connectionStrings>-->
      <system.web>
      <trust level="Full"/>
            <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.

            Visual Basic options:
            Set strict="true" to disallow all data type conversions
            where data loss can occur.
            Set explicit="true" to force declaration of all variables.
        -->
            <customErrors defaultRedirect="~/Default.aspx"/>
            <roleManager enabled="true"/>
            <compilation debug="true">
                  <assemblies>
                        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add assembly="System.IO.Log, Version=3.0.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                  </assemblies>
            </compilation>
            <pages>
                  <namespaces>
                        <clear/>
                        <add namespace="System"/>
                        <add namespace="System.IO"/>
                        <add namespace="System.Collections"/>
                        <add namespace="System.Collections.Generic"/>
                        <add namespace="System.Collections.Specialized"/>
                        <add namespace="System.Configuration"/>
                        <add namespace="System.Core"/>
                        <add namespace="System.data.sql"/>
                        <add namespace="System.Text"/>
                        <add namespace="System.Text.RegularExpressions"/>
                        <add namespace="System.Linq"/>
                        <add namespace="System.Xml.Linq"/>
                        <add namespace="System.xml"/>
                        <add namespace="System.Xml.Serialization"/>
                        <add namespace="System.Xml.Schema"/>
                        <add namespace="System.Xml.Xpath"/>
                        <add namespace="System.Xml.Xsl"/>
                        <add namespace="System.Web"/>
                        <add namespace="System.Data"/>
                        <add namespace="System.Data.DataSetExtensions"/>
                        <add namespace="System.Web.Caching"/>
                        <add namespace="System.Web.SessionState"/>
                        <add namespace="System.Web.Security"/>
                        <add namespace="System.Web.Profile"/>
                        <add namespace="System.Web.UI"/>
                        <add namespace="System.Web.UI.WebControls"/>
                        <add namespace="System.Web.UI.WebControls.WebParts"/>
                        <add namespace="System.Web.UI.HtmlControls"/>
                  </namespaces>
                  <controls>
                        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                  </controls>
            </pages>
            <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
            <authentication mode="Forms"/>
            <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
            <httpHandlers>
                  <remove verb="*" path="*.asmx"/>
                  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? " validate="false"/>
            </httpHandlers>
            <httpModules>
                  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
            </httpModules>
      </system.web>
      <system.codedom>
            <compilers>
                  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=???????????????? ">
                        <providerOption name="CompilerVersion" value="v3.5"/>
                        <providerOption name="OptionInfer" value="true"/>
                        <providerOption name="WarnAsError" value="false"/>
                  </compiler>
            </compilers>
      </system.codedom>
      <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
      <system.webServer>
            <validation validateIntegratedModeConfiguration="false"/>
            <modules>
                  <remove name="ScriptModule"/>
                  <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
            </modules>
            <handlers>
                  <remove name="WebServiceHandlerFactory-Integrated"/>
                  <remove name="ScriptHandlerFactory"/>
                  <remove name="ScriptHandlerFactoryAppServices"/>
                  <remove name="ScriptResource"/>
                  <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                  <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
                  <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????????? "/>
            </handlers>
      </system.webServer>
      <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                  <dependentAssembly>
                        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="???????????????? />
                        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
                  </dependentAssembly>
                  <dependentAssembly>
                        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="???????????????? "/>
                        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
                  </dependentAssembly>
            </assemblyBinding>
      </runtime>
</configuration>

0
 
CodeCruiserConnect With a Mentor Commented:
Your authentication element is supposed to be like this

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx"
           protection="All"
           timeout="30"
           name=".ASPXAUTH"
           path="/"
           requireSSL="false"
           slidingExpiration="true"
           defaultUrl="default.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" />
  </authentication>
</system.web>


instead of just
 <authentication mode="Forms"/>
0
 
CodeCruiserCommented:
where you can change defaultUrl = "Browser.aspx"
0
 
Alfred A.Connect With a Mentor Commented:
When you set authentication mode to "Forms", this will trigger Forms Authentication.  Since you don't have any configuration for the forms tag, you will have problems redirecting.  And this is why your redirect is not working.

Also, with your approach, it seems you are doing your own Custom Authentication.  If that is the case then you should have this in your web.config:

<system.web>
   <authentication mode="None" />
</system.web>

There are other modes of authentication such as Windows and Passport.  Check the following for pros and cons of ASP.NET authentication mode:

http://msdn.microsoft.com/en-us/library/aa291347%28VS.71%29.aspx
0
 
Alfred A.Commented:
Also, if you will use Forms Authentication, it is better for you to use RedirectFromLoginPage once login is successful.  Check this out:

http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx

http://msdn.microsoft.com/en-us/library/1f5z1yty.aspx
0
 
MOSSPOINTAuthor Commented:
Thanks for all your contributions, really helped.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.