Link to home
Start Free TrialLog in
Avatar of MOSSPOINT
MOSSPOINTFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to set the second parameter to false, otherwise the standard login stuff will take over and stop your redirect working.
Let me try that again! You need to set the second parameter to TRUE, rather than FALSE

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.




ASKER CERTIFIED SOLUTION
Avatar of buraksarica
buraksarica
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MOSSPOINT

ASKER

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")
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.
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.
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.
OK, the try raises the following exception?

System.Threading.ThreadAbortException      {Property evaluation failed.}
Please share your web config in order to let us understand your authentication details. How you secure the pages through forms auth.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
where you can change defaultUrl = "Browser.aspx"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thanks for all your contributions, really helped.