Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL redirection issue

Status
Not open for further replies.

Everton1Blue

Technical User
Jun 6, 2014
41
GB
Hello

How would I identify a URL redirection error that needs correcting in my code, please? I can't see anything in my Visual Studio code or when I press F12 online - the relevant page is here:
I have not come across this error before (server error 301?) and am not even sure what I am looking for.

The problem I have is that when the form is completed and 'Send' is pressed, the user is not redirected to my thankyou.aspx page. The email code is never actually processed due to the URL redirection error, and so remains in the address bar. That is what I need to correct.

Do I need to change my Web.config file in any way? I am in the dark about this error.

Thanks!
 
Everton,

What is your redirection code so we can help troubleshoot? Response 301 can certainly stem from a redirection issue. Also, is this VB-related? I deal with a lot of PHP and SQL information, so I am assuming that header redirection is how you are processing this? I am not terribly familiar with ASP, but I am guessing that it is closely related somehow. :) Hopefully we can help narrow down any issue.

Also, if it is of any value to you, I submitted a test entry on the URL you provided and it did not present the error to me. It simply routed me back to the same page.
 
Thanks for your reply, Pixel God.

Yes, you don't actually get any error when you click on send but the problem is what you have identified: it routed you back to the same page and not to the thank you page. That's because it's 'stuck' due to the redirection back to the contact form page.

Yes, it is vb.net related but I don't think the issue it directly related to vb.net - not to the code.

The redirection code I have is this:

Code:
Dim target = String.Format("~/thankyou.aspx?your_name={0}", yourname)

        Response.Redirect(String.Format("~/thankyou.aspx?your_name={0}", yourname), True)

But as I say, that is not even read because the browser does not leave the contact page. None of the SMTP code (tested and fine) is processed. I am not sure what you mean by 'header redirection' but various online tutorials do refer to that.
 
Looking at the HTML/Javascript for the page this is what I see happening.

1. User fills out form and hits submit
2. Javascript validation runs - if successful form is processed (a quick glance seems that validation may be off - perhaps for testing purposes)
3. The form data is submitted to "contact.aspx" - the same page that is hosting the form (the "action" attribute of the form element).

So as far as I can see there is no redirection occurring anywhere (unless it is happening within the contact.aspx server side code. (I filled out the form to attempt to log any redirects, but the fake email I used triggered an aspx SmtpException "Sending address not accepted due to spam filter")
 
Could you post the code in the Send button's event handler, and/or and methods that may get called when Send is clicked? That's where you should have the Response.Redirect by the way, in the event handler for the Send button.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Many thanks to you both for your replies.

I am not sure where the SmtpException has come from! It's not part of the code that I have done! There is no validation or Captcha at the moment. I just wanted to ensure the form could be sent before going further with it. Yes, the server side code (vb.net) should redirect the user - please see below.

Code:
contact.aspx:

<asp:Button ID="contact_submitted" runat="server" name="contact_submitted" type="submit" Text="Send" OnClick="contact_submitted_Click" />


contact.aspx.vb:

Protected Sub contact_submitted_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles contact_submitted.Click

        SMTP code here
        ......
       Smtpserver.Send(myMessage)

        myMessage.Dispose()
        myMessage = Nothing
        Smtpserver = Nothing

        Dim target = String.Format("~/thankyou.aspx?your_name={0}", yourname)

        Response.Redirect(String.Format("~/thankyou.aspx?your_name={0}", yourname), True)

    End Sub

As I say, this is probably not even read because as soon as the 'Send' button is pressed the form data is submitted to contact.aspx and not to thankyou.aspx, but I can't see what is causing that to happen. If I can't see it in Visual Studio or in F12 online (it's temporarily down), how would I identify an erroneous redirect so that I can correct it?

Thanks again to you both.
 
Everton1Blue,

From what I gather, [tt]Response.Redirect[/tt] will result in an HTTP error if headers have already been sent. Does [tt]HttpResponse.BufferOutput[/tt] return anything of value that may help you pinpoint where the error is occurring? Sorry if I am approaching this due to my vague understanding of ASP, but perhaps a different perspective may help. :)
 
Hello PixelGod

Thanks again.

Yes, any different perspective is welcome.

No errors are generated.

In my contact form page, where would I place HttpResponse.BufferOutput?

Thanks!
 
Everton1Blue,

I would assume that you put it in your contact.aspx.vb file after the Redirect code in this format:

Code:
Response.Redirect(String.Format("~/thankyou.aspx?your_name={0}", yourname), True)

HttpResponse.BufferOutput = True

With any luck it will dump any information regarding what the page is having issues with when processing the redirection out to your screen. Should help with any troubleshooting. Another suggestion I scrambled-up after searching the web was:

Code:
Response.Redirect(String.Format("~/thankyou.aspx?your_name={0}", yourname), True)

Response.End

Taken from How to use Response Redirect in a server script, it seems that the code is never actually sent unless this tid-bit is placed in the code! I hope this helps. :)
 
Hello Pixel God

That sounds promising.

Please give me a short while, I will try it, and get back to you.

Thanks again!
 
I have delayed replying because I am waiting for a response from my Web hosting service.

I slimmed down my project and uploaded it again. I am now getting the message that you got:

SmtpException "Sending address not accepted due to spam filter"

Hopefully, that means the URL redirect problem has disappeared!

 
Great news! Make sure you follow-up with what fixed your issue so if anyone else stumbles across this forum looking-up the same issue they can get pointed in the right direction for the fix.
 
OK, it's now resolved.

I greatly simplified the project by deleting files in Solution Explorer (files relating to Twitter, Register.aspx, Login.aspx, etc) that my project does not use at the moment. I presume I can add them later if I wish?). ONce I had done that, the URL redirect problem disappeared.

I also needed to 'register' the Webmaster's email address (the recipient of the contact form's email) in what my Web hosting service calls a safe/white area of my Email programme (SmarterMail?). I had no idea about it!

What I have to do now is resolve how to display, and get working, Google's reCaptcha. I didn't want to do that until I knew that the email could be processed correctly (the reCaptcha would have just complicated things).

Many thanks again to you all for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top