Solved

Response redirect does not appear to execute

Posted on 2010-11-25
17
1,049 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:MOSSPOINT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +3
17 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34211431
You need to set the second parameter to false, otherwise the standard login stuff will take over and stop your redirect working.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34211433
Let me try that again! You need to set the second parameter to TRUE, rather than FALSE
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34211451

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
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 
LVL 5

Accepted Solution

by:
buraksarica earned 125 total points
ID: 34211592
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
 

Author Comment

by:MOSSPOINT
ID: 34212155
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
 
LVL 5

Expert Comment

by:buraksarica
ID: 34212233
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34212261
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
 
LVL 21

Expert Comment

by:Alfred1
ID: 34212861
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
 

Author Comment

by:MOSSPOINT
ID: 34213148
OK, the try raises the following exception?

System.Threading.ThreadAbortException      {Property evaluation failed.}
0
 
LVL 5

Expert Comment

by:buraksarica
ID: 34215923
Please share your web config in order to let us understand your authentication details. How you secure the pages through forms auth.
0
 
LVL 21

Assisted Solution

by:Alfred1
Alfred1 earned 250 total points
ID: 34224974
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
 

Author Comment

by:MOSSPOINT
ID: 34228940
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
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 125 total points
ID: 34228949
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34228954
where you can change defaultUrl = "Browser.aspx"
0
 
LVL 21

Assisted Solution

by:Alfred1
Alfred1 earned 250 total points
ID: 34229283
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
 
LVL 21

Expert Comment

by:Alfred1
ID: 34229302
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
 

Author Closing Comment

by:MOSSPOINT
ID: 34255480
Thanks for all your contributions, really helped.
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question