Redirect request to 'ReturnUrl' displays Login Page

血红的双手。 提交于 2019-12-24 00:50:02

问题


I am trying to test simple changes to a web page, locally. I am using VS 2008 and VB.net. I enter the page that I would like to go to. But it needs a login, so it correctly takes me to the login page. I can successfully login using a test account. Then it redirects to the 'ReturnUrl' but the page that is displayed is the login page, not the one listed in the address bar which is the correct value - 'ReturnUrl' variable.

I tried using Fiddler2 to see if there are any problems, but there are not. It shows the redirection to the proper page and the URL is the page I want to see but what is displayed in the browser (FireFox) is the Login page.

Here is the code that redirects the page:

If Request.QueryString("ReturnUrl") = "" Then
    Response.Redirect("profile.aspx")
Else
    Response.Redirect(Request.QueryString("ReturnUrl"))
End If

I checked the ReturnUrl value and it is the correct url. No errors are displayed but the Login page is shown with the text boxes of the Login page (profile.aspx) cleared. The URL shown in the window is the 'ReturnUrl'.

Does anybody have an idea of what is going wrong?


回答1:


tried a lot of suggestions. only this worked. place code at your default.aspx page.

 Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    Dim strRedirect As String

    strRedirect = Request.QueryString("ReturnUrl")

    If (strRedirect <> "") Then

        Response.Redirect("~/Default.aspx", True)

    End If

End Sub



回答2:


For any poor souls who are struggling with this issue, this is what worked for me...

I am running this locally. That is the key! In my code, there were 2 cookies created before the .Redirect method call: The code looked like this:

 Dim C As HttpCookie
 C = FormsAuthentication.GetAuthCookie(custID.ToString, False)
 C.Domain = "ourdomain.com"
 Response.AppendCookie(C)

 Dim C2 As System.Web.HttpCookie = New System.Web.HttpCookie("ProfileUsername", P.UserName)
 C2.Domain = "ourdomain.com"
 Response.AppendCookie(C2)

I needed to change the .Domain to ".localhost". It MUST have at least one dot in the name.

Also, in the web.config file, in the element authentication. The 'mode' is 'Forms'. An attribute of 'Forms' is domain=".localhost"

That got my test to accept my test member and move on to the part of the code that I needed to test.



来源:https://stackoverflow.com/questions/22357853/redirect-request-to-returnurl-displays-login-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!