Sign in to follow this  
Xest

[web] ASP QueryString/POST data queries

Recommended Posts

Xest    140
Hi there, I have two queries, I'm fairly new to ASP but not programming in general, I've had a look through Google and such but ASP.NET seems to get all the hits there. My first query is, is there a proper way to build a query string to be sent as part of a response.redirect or are you meant to just manually build it using a string and then submit this manually built URL+QueryString string as your response.redirect target? My second query is, is it possible to redirect to a different ASP page and submit a POST data QueryString? I have a login form on my site which submits the form to a seperate ASP page to process the login, I also have a signup form, when signup is complete and signup details have been validated and recorded into the database I'd like to just submit the username and password from the completed signup form to my existing login processing asp file which accepts POST data (because I don't want the username and password in the QueryString!). Hope someone can help! Thanks.

Share this post


Link to post
Share on other sites
markr    1692
Quote:
Original post by Xest
My first query is, is there a proper way to build a query string to be sent as part of a response.redirect or are you meant to just manually build it using a string and then submit this manually built URL+QueryString string as your response.redirect target?


Is there a function to urlencode strings in ASP? (Something like Server.UrlEncode?) If so, then use that to encode the parameters appropriately before calling Response.Redirect

Quote:

My second query is, is it possible to redirect to a different ASP page and submit a POST data QueryString? I have a login form on my site which submits the form to a seperate ASP page to process the login, I also have a signup form, when signup is complete and signup details have been validated and recorded into the database I'd like to just submit the username and password from the completed signup form to my existing login processing asp file which accepts POST data (because I don't want the username and password in the QueryString!).


You can't force a post except by serving a page containing a form with hidden fields and javascript (or requiring the user to press a button if JS is not enabled). This is inconvenient, but still the method used by many sites (e.g. for Paypal external payments).

You should really consider refactoring your code so you don't have to do this - for example, put the code to perform the logon into a subroutine shared by the two pages, and simply insert a call to it. This seems like a better way, structurally.

Mark

Share this post


Link to post
Share on other sites
Xest    140
Hi markr, thanks for the response!

It's not so much about URL encode, I was just wondering if ASP had a set of functions to allow building a query string i.e. something like addQueryStringItem(name, value) which would handle adding the ? after the .asp file, sticking ampersands between items and such, I've done this myself now but using an official ASP built in function would've been a cleaner option.

In terms of the second comment my code is already refactored as it were, I was just wondering if you could post data between one asp page to another as this seems like good code reuse practice being able to use my login processor page in both situations. I agree, the method you mentioned really isn't ideal so I'll stick to what I've got, it results in some code duplication but not much to be that big an issue.

I should've probably been more clear, it's not so much the solutions to the problems that had me stumped but more that I was trying to adhere to good programming practice - ASP doesn't seem to be the best language I've ever used for that type of thing although I'm sure it's also partly that I've just not been using ASP long enough to 'get' ASP's way, or the web development way of doing things in general perhaps ;)

Share this post


Link to post
Share on other sites
markr    1692
Doing something yourself isn't bad practice if you do it in a maintainable, clear way. I doubt if there is a function to construct query strings (There isn't a function for very much in ASP).

Reusing code by putting it into a subroutine sounds like a much better idea than getting the client browser involved and redirecting them to the logon page.

You should probably reuse code by creating common subroutines or classes* - rather than having redirects etc.

Mark

* If indeed, ASP and your scripting language allow you to create classes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this