Bookmarking ASP.NET search results using POST or GET? - asp.net

I need a little help understanding how HTML forms work. It is my understanding that forms that use GET as their method submit name/value pairs for all fields within the form tags of said submission. However, if you take a look at the follow example from Google (and I've seen this in many other places too) and only use one of the fields on the form:
http://books.google.co.uk/advanced_book_search
Rather than being sent to a page with a name/value pair for each field of the advanced search page you are taken to a much cleaner looking URL:
http://www.google.co.uk/search?tbo=p&tbm=bks&q=hitchiker&num=10
Despite all of the input fields on the advanced search page.
Onto my problem... My own advanced search page is quite large and at the moment is being POSTed to my search results page which is taking in the values and searching accordingly, no problems! However, I want my users to be able to bookmark/share their searches and in order to do this I need to have items being passed into the querystring but I don't want massive querystrings if I don't need them. If my user has only searched by a color for example then I want the URL to be something like search.aspx?color=red; If they're searching by color and size then search.aspx?color=red&size=large and so on. Is this possible?
To complicate things even further I'm using ASP.NET so it's not the easiest of things to create a form that uses GET though I do believe I have already found away around this.
If you can give any advice or a nudge in the right direction, then thank-you! :)

What you're suggesting should be easily possible if you conditionally check the querystring on the results page to ensure the key/value is there.
if(Request.QueryString["color"] != "")
{
// Add color to the seach parameters
}
To create the GET request I would think you would need to POST back to your search form and redirect to the results form from there, dynamically adding key/values to the querystring as and when they are required. This Post/Redirect/Get design pattern is typically used with web forms to help with book marking.

If you want to share bookmarked searches between users, then you'll have to share the name/value querystring options in the posted URL. It sounds like you don't want to include the pair if one wasn't specified. That's easy, just dynamically build a querystring for pairs that the user HAS provided input for. So, when processing, loop through all input controls, and if a value was provided, append it to the querystring, or not.

Related

How to make form like example

there is this site https://www.delinski.at/ and it has a nice form where you can pick some values from dropdowns like Date, Number of Persons etc., and then submit the form. It redirects and I see the values on the redirected page link as parameters (if I have changed the defaults).
I searched for and tried several Form Plugins which all do not seem to work - most recent one (Form Maker) lets me design the form as I want but at the end I realized when I click on Submit, the values are not transfered to the target page (confirmed by Form Maker Support as work as intended). It's confusing because actually that should be a basic funciontality of a HTML form, right?
So I want to know if there are plugins where I can get a similar look&feel like the example given above.
That site is a Static Site Generated framework not WordPress. That site would also be very expensive to build cause that is all coded, and very well:)
You are not actually seeing a form there at all that is just how PHP natively uses the URL to navigate via a button.
Almost all the form plug ins for WP use the database write now and do not pass the parameters of the entered form as a php _ POST with a redirect.
I kind of think what you really are looking for is a faceted search feature
One of the best that comes to my mind is https://facetwp.com/demo/cars/?_vehicle_type=truck
Notice the car icons those are actually search buttons:) Of course you will have to build a template to do that neat stuff on the SSG site you linked but...
here is a really informative write upon how it works to get started.

Directory/file names confusion

I wasn't sure how to word this but the easiest way to describe what I mean is just by giving an example.
Take this site -> http://lolprofile.net/summoner/lan/rimortix . When you search for a summoner the user in this case rimortix changes but the page renders the same just with a different users info. They don't use index.php?user=rimortix which would make sense to me on how it would work. How do they dynamically query for user info in this url layout?
The site I used was just an example but I have seen this same layout many times.
I came across this and it was exactly what I was going for.
Dynamic url in php without filename

Webscraping a tricky asp.net page

The overall goal is to perform a search on the following webpage http://www.cma-cgm.com/eBusiness/Tracking/Default.aspx with a container value of CMAU1173561. I have tried two approaches, the php extension cURL and python's mechanized. The php approached involves a performing a POST submit using the input fields found on the page (NOTE: These are really ugly on the asp.net page). The returned page does not contain any of the search results. The second approaches involves using python's mechanize module. In this approach I load the page, select the form, then change the text field ctl00$ContentPlaceBody$TextSearch to the container value. When I load the response again no search results.
I am at a really dead end. Any help would be appreciate because as it stands my next step is to become a asp.net expertm which i perfer not to.
The source of that page is pretty scary (giant viewstate, tables all over the place, inline CSS, styles that look like they were copied from Word).
Regardless...an ASP.Net form still passes the same raw data to the server as any other form (though it is abstracted to the developer).
It's very possible that you are missing the cookies which go along with the request. If the search page (or any piece of the site) uses session state, the ASP.Net session cookie must be included in the request. You will be able to tell it from its name (contains "asp.net" and "session").
I assume that you have used a tool like Firebug or Chrome to view the complete outgoing request when the page is submitted. From my quick test, it looks like the request may be performed with a GET, not a POST. I submitted a form, looked at the request, and pasted the URL into a new browser window.
Example: http://www.cma-cgm.com/eBusiness/Tracking/Default.aspx?ContNum=CMAU1173561&T=57201202648
This may be all you need to do.

ASP.NET 4.0 URL Rewriting: How to deal with the IDs

I have just started adding the new .NET 4.0 URL Rewriting into my project. I have a question.
Let's say I have a Article.aspx that displays, well, articles. I made a route for it in the Global.asax:
routes.MapPageRoute("article-browse", "article/{id}", "~/Article.aspx");
So the link consists of the article's id which is, obviously, not a very nice, nor SEO friendly link. I would like to display the Article's title in the link, instead of the ID.
Do I have to pass the whole title in the parameter (instead of the id) and then make a SQL query that searches for a database record with the matching title? That sounds scary. Maybe there is some way to do something similar to the Eval() methods, that would change the title into an ID?
Thank you very much!
There is nothing to prevent you from including both the ID (for quick SQL retrieval) and the article's title in the link (for SEO purposes). This is exactelly how stackoverflow is handling the routing (check the address for this question).
routes.MapPageRoute("article-browse", "article/{id}/{title}", "~/Article.aspx");
Obviously, the title after the ID is not necessary to display the page (you only use the ID to fetch the article), but everytime you generate the link in your site, generate it with the title, and the bots will use that when indexing your pages.
Oh, and you might also want to create a method that translates your title into a URL-friendly string.Like making all lowercase, converting spaces and other characters to '-',etc.

Ways to track the referring page to create other links?

I need to be able to determine which page the user just came from to determine which links to display, such as breadcrumbs or links to the previous next item. This is basically the HTTP_REFERER functionality in PHP, but I need a way of tracking it across multiple pages. I also need to "support" the back button.
I have noticed that Facebook uses a query/get parameter of "ref" to track the referring page. (They also avoid reloading the entire page, using AJAX instead but I'm don't have the budget to do that right now.) Also, the site I'm working on needs to be indexed by Google, so this method will also require that I add the canonical link tag.
I'm wondering if the ref/referrer query parameter is the best method or what other options there are?
If you want breadcrumbs, you shouldn't be using HTTP_REFERER at all. It should be a logical path to get to where they are, no matter where they came from, like User > Albums > AlbumName > Photo, even if they came from a direct link their friend gave them. That said, if you do want to go back a few pages, just store them as a an array in a SESSION variable.
I'm pretty sure Facebook just uses the ref GET variable to collect some statistics on which buttons users are using, since there are multiple ways to get to the same page.
None of this should break the back button, or intefere with your canonical tag.
From comments: You could use a ?ref=blah tag, or session variables, ($_SESSION['history'][0] = $_SERVER['HTTP_REFERER'] or REQUEST_URI). Use whatever you find easiest. Session variables rely on cookies or passing an ID through the URL, GETs just clutter the URL and might get passed around to friends.

Resources