MOSSPOINT
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("Browse r.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("customerConf igFilePath ") = Server.MapPath("~") & "\XML files\CustomerFile.xml"
Session.Item("customerProj ectsFile") = Server.MapPath("~") & "\XML files\Projects.xml"
'Response.Redirect("Browse r.aspx")
HttpContext.Current.Respon se.Redirec t("Browser .aspx", False)
End Sub
End Class
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("Browse
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("customerConf
Session.Item("customerProj
'Response.Redirect("Browse
HttpContext.Current.Respon
End Sub
End Class
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("Br
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chaps,
Thanks for the responses unfortunately none work.
I tried, HttpContext.Current.Respon se.Redirec t("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("Br owser.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("customerConf igFilePath ") = Server.MapPath("~") & "\XML files\CustomerFile.xml"
Session.Item("customerProj ectsFile") = Server.MapPath("~") & "\XML files\Projects.xml"
'Response.Redirect("Browse r.aspx")
HttpContext.Current.Respon se.Redirec t("Browser .aspx", True)
'this.response.redirect("B rowser.asp x")
Thanks for the responses unfortunately none work.
I tried, HttpContext.Current.Respon
I tried, this.response.redirect("Br
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("customerConf
Session.Item("customerProj
'Response.Redirect("Browse
HttpContext.Current.Respon
'this.response.redirect("B
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.Applic ationInsta nce.Comple teRequest( )
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.
Response.Redirect("Browser
HttpContext.Current.Applic
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
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.
ASKER
OK, the try raises the following exception?
System.Threading.ThreadAbo rtExceptio n {Property evaluation failed.}
System.Threading.ThreadAbo
Please share your web config in order to let us understand your authentication details. How you secure the pages through forms auth.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\Fra mework\v2. x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extension s" type="System.Web.Configura tion.Syste mWebExtens ionsSectio nGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? ">
<sectionGroup name="scripting" type="System.Web.Configura tion.Scrip tingSectio nGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ?????>
<section name="scriptResourceHandle r" type="System.Web.Configura tion.Scrip tingScript ResourceHa ndlerSecti on, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? " requirePermission="false" allowDefinition="MachineTo Applicatio n"/>
<sectionGroup name="webServices" type="System.Web.Configura tion.Scrip tingWebSer vicesSecti onGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? ">
<section name="jsonSerialization" type="System.Web.Configura tion.Scrip tingJsonSe rializatio nSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? " requirePermission="false" allowDefinition="Everywher e"/>
<section name="profileService" type="System.Web.Configura tion.Scrip tingProfil eServiceSe ction, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? " requirePermission="false" allowDefinition="MachineTo Applicatio n"/>
<section name="authenticationServic e" type="System.Web.Configura tion.Scrip tingAuthen ticationSe rviceSecti on, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? " requirePermission="false" allowDefinition="MachineTo Applicatio n"/>
<section name="roleService" type="System.Web.Configura tion.Scrip tingRoleSe rviceSecti on, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? " requirePermission="false" allowDefinition="MachineTo Applicatio n"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
</appSettings>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=s02.ServiceProvider .com;Initi al Catalog=DB_4996_company;Us er ID=DB_4996_company_user;Pa ssword=??? ??????;Int egrated Security=False;"/>
</connectionStrings>
<!--connectionStrings>
<add name="EMVConnectionString" connectionString="Data Source=.\SQLEXPRESS;Attach DbFilename =|DataDire ctory|\tes ting.mdf;I ntegrated 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.Exten sions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
<add assembly="System.Data.Data SetExtensi ons, 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.F orms, 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.Collecti ons"/>
<add namespace="System.Collecti ons.Generi c"/>
<add namespace="System.Collecti ons.Specia lized"/>
<add namespace="System.Configur ation"/>
<add namespace="System.Core"/>
<add namespace="System.data.sql "/>
<add namespace="System.Text"/>
<add namespace="System.Text.Reg ularExpres sions"/>
<add namespace="System.Linq"/>
<add namespace="System.Xml.Linq "/>
<add namespace="System.xml"/>
<add namespace="System.Xml.Seri alization" />
<add namespace="System.Xml.Sche ma"/>
<add namespace="System.Xml.Xpat h"/>
<add namespace="System.Xml.Xsl" />
<add namespace="System.Web"/>
<add namespace="System.Data"/>
<add namespace="System.Data.Dat aSetExtens ions"/>
<add namespace="System.Web.Cach ing"/>
<add namespace="System.Web.Sess ionState"/ >
<add namespace="System.Web.Secu rity"/>
<add namespace="System.Web.Prof ile"/>
<add namespace="System.Web.UI"/ >
<add namespace="System.Web.UI.W ebControls "/>
<add namespace="System.Web.UI.W ebControls .WebParts" />
<add namespace="System.Web.UI.H tmlControl s"/>
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Exten sions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
<add tagPrefix="asp" namespace="System.Web.UI.W ebControls " assembly="System.Web.Exten sions, 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="GenericEr rorPage.ht m">
<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.Se rvices.Scr iptHandler Factory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Se rvices.Scr iptHandler Factory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers. ScriptReso urceHandle r, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? " validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers. ScriptModu le, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="vb;vbs;visualbas ic;vbscrip t" extension=".vb" warningLevel="4" type="Microsoft.VisualBasi c.VBCodePr ovider, 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 validateIntegratedModeConf iguration= "false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandl er" type="System.Web.Handlers. ScriptModu le, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
</modules>
<handlers>
<remove name="WebServiceHandlerFac tory-Integ rated"/>
<remove name="ScriptHandlerFactory "/>
<remove name="ScriptHandlerFactory AppService s"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory " verb="*" path="*.asmx" preCondition="integratedMo de" type="System.Web.Script.Se rvices.Scr iptHandler Factory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
<add name="ScriptHandlerFactory AppService s" verb="*" path="*_AppService.axd" preCondition="integratedMo de" type="System.Web.Script.Se rvices.Scr iptHandler Factory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
<add name="ScriptResource" preCondition="integratedMo de" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers. ScriptReso urceHandle r, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=??????????? ????? "/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microso ft-com:asm .v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extension s" publicKeyToken="?????????? ?????? />
<bindingRedirect oldVersion="1.0.0.0-1.1.0. 0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extension s.Design" publicKeyToken="?????????? ?????? "/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0. 0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
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\Fra
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extension
<sectionGroup name="scripting" type="System.Web.Configura
<section name="scriptResourceHandle
<sectionGroup name="webServices" type="System.Web.Configura
<section name="jsonSerialization" type="System.Web.Configura
<section name="profileService" type="System.Web.Configura
<section name="authenticationServic
<section name="roleService" type="System.Web.Configura
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
</appSettings>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=s02.ServiceProvider
</connectionStrings>
<!--connectionStrings>
<add name="EMVConnectionString"
</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
<roleManager enabled="true"/>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=???????????
<add assembly="System.Web.Exten
<add assembly="System.Data.Data
<add assembly="System.Xml.Linq,
<add assembly="System.IO.Log, Version=3.0.0.0, Culture=neutral, PublicKeyToken=???????????
<add assembly="System.Windows.F
<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.Collecti
<add namespace="System.Collecti
<add namespace="System.Collecti
<add namespace="System.Configur
<add namespace="System.Core"/>
<add namespace="System.data.sql
<add namespace="System.Text"/>
<add namespace="System.Text.Reg
<add namespace="System.Linq"/>
<add namespace="System.Xml.Linq
<add namespace="System.xml"/>
<add namespace="System.Xml.Seri
<add namespace="System.Xml.Sche
<add namespace="System.Xml.Xpat
<add namespace="System.Xml.Xsl"
<add namespace="System.Web"/>
<add namespace="System.Data"/>
<add namespace="System.Data.Dat
<add namespace="System.Web.Cach
<add namespace="System.Web.Sess
<add namespace="System.Web.Secu
<add namespace="System.Web.Prof
<add namespace="System.Web.UI"/
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.H
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Exten
<add tagPrefix="asp" namespace="System.Web.UI.W
</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="GenericEr
<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.Se
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Se
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="vb;vbs;visualbas
<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 validateIntegratedModeConf
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandl
</modules>
<handlers>
<remove name="WebServiceHandlerFac
<remove name="ScriptHandlerFactory
<remove name="ScriptHandlerFactory
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory
<add name="ScriptHandlerFactory
<add name="ScriptResource" preCondition="integratedMo
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microso
<dependentAssembly>
<assemblyIdentity name="System.Web.Extension
<bindingRedirect oldVersion="1.0.0.0-1.1.0.
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extension
<bindingRedirect oldVersion="1.0.0.0-1.1.0.
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
where you can change defaultUrl = "Browser.aspx"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx
http://msdn.microsoft.com/en-us/library/1f5z1yty.aspx
ASKER
Thanks for all your contributions, really helped.