Custom 404 pages not being able to postback due to relative path issues - postback

My site currently implements custom 404 pages which we have mapped in IIS. So when a user does something like www.mysite.com/foo/bar/doesnotexist, it will execute the 404.aspx URL. This works great, but when inspecting the HTML returned, the form post URL is relative:
<form method="post" action="404.aspx?404%3bhttps%3a%2f%2ftestserver%3a443%2ffoo%2fbar%2fdoesnotexist" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
If you look closely the action URL is posting to the 404.aspx but it's a relative path, so it is trying to execute if we do a postback www.mysite.com/foo/bar/doesnotexist/404.aspx. How do I get my executed 404 pages to postback properly? (www.mysite.com/404.aspx)
Thanks.

Victor,
Your question is a duplicate so I think you will probably find your answer here.
Since you are new here hopefully the close Nazi's will cut you some slack. Basically when you write a question there should be a list of similar questions that pop-up right under your question. If you see a question that looks like it may answer your own, follow the link and check it out before you post. 9 out of 10 times your question may have already been answered.
Good luck in finding your answer, I think there should be a lot of good information on that link.

This can also happen if you are using axjx and pulling one page into another and the pages are in diffrent directories, easy way round it is rewrite the forms action object on page load from the root of your web site.
e.g.
//Rewirte forms post action.
form1.Action = "/{dir}/{currentpage}.aspx?" + Request.QueryString;

Related

Google cant find any pages in my mvc

Hi I have a homepage that is just now working with google.
When I type following into a google search box "site:http://www.nameofmysite.com", I get Page not found.
Google is not able to index a single page in my whole site. I have many pages in my site.
However if you just browse my site it looks good, things are working nicely.
I have a MVC 3 site, I have made it multilanguage and the language parameter en, sv, es etc, is reflected in the url, something like www.nameofmysite.com/en/ContactMail
I'm not posting any code, since I do not know if the problem lays in the code or something else. If anyone would like me to post code, then please let me know.
Hope someone can shed some light on to this.
Thanks.
I have had my questions answered in another thread.
International version of NerdDinner
The problem was that in my basecontroller and global.asax file I had some code that was returning null values if fetched by google bot.

Submit webform via URL only?

I'm not really sure this belongs here, so instead of downvoting just lemme know if so and I'll quickly move it on.
Anyway, there is a website that has a search page, that when hitting the search button it doesn't include the search query in the URL.
After searching for something, the page is redirected to ssearch.asp, but as said, the query isn't there.
My question is if there is a way to submit the search values solely via URL.
I was wondering if there is a way to fake the search-submit button and post the search term
via URL according to form field names.
The name of the input box is search, so I tried this URL: http://www.torec.net/ssearch.asp?search=query, but it doesn't work, the server returns:
server error.
Just to be clear, I'm not looking for a server-side solution, and actually nor for a HTML solution, I just want to be able to paste a plain old URL in my browsers address bar and be there.
Is this possible?
Update
This link doesn't work:
http://www.torec.net/ssearch.asp?search=dark&page=1
While this one does:
http://www.torec.net/ssearch.asp?search=dark&page=2
Any way to bypass this?
Sometimes servers conflate GET and POST parameters, as in PHP $_REQUEST hash. However, normally they are separate - and a server that expects its parameters in multipart/form-data might not look at URL at all. In such a case, as it seems to be here, you have to construct a POST request. On the client side you can do it through AJAX or through constructing and posting a form; on the server side, you can use curl, or a library. You did not say what you want to use it for (and where you want to use it), so you just get the general answer, I'm afraid.
EDIT: Here is the JavaScript semi-solution. You have to already be on some page (i.e. can't use it on _blank), and I'm not sure if it works on all browsers.
javascript:d=document;f=d.createElement("form");h=d.createElement("input");f.setAttribute("method","post");f.setAttribute("enctype","application/x-www-form-urlencoded");f.setAttribute("action","http://www.torec.net/ssearch.asp");h.setAttribute("type","hidden");h.setAttribute("name","search");h.setAttribute("value","query");f.appendChild(h);d.body.appendChild(f);f.submit();
Edit: It is not possible to create a link directly to the first page. However, you can easily send a user to the first page by by creating a form:
<form id="postForm" method="post" action="http://www.example.com/search">
<input type="text" name="search" value="q">
</form>
And then submitting the form whenever the user clicks a psuedo-link:
document.getElementById("postForm").submit();
This can also be done by typing JavaScript code into the address bar:
javascript:a=document.createElement("form");a.method="POST";a.action="http://www.torec.net/‌​ssearch.asp?search=dark&page=2";i=document.createElement("input");i.name="search";i.value="q";a.appendChild(inpu‌​t);a.submit();

How relative link in href working?

I have a problem relating to relative links in href. To make a long story short, I think an example is the best way to get what's going on.
On tinhte.vn/threads/300021/, it is a discussion forum, to go to the page 2, we click on [2].
I view source code of [2], its content is 2.
If I do not misunderstand about relative links, this will append threads/30021/page-2 after the current link, which is tinhte.vn/threads/30021/, and we have the link like this:
tinhte.vn/threads/300021/threads/300012/page-2
But in practice, when I do in the browser, mine is chrome, the link is:
tinhte.vn/threads/300012/page-2
Anyone please explain why?
Sorry, due to the spam prevention, I cannot post direct link.
Thanks in advance.
The link will correctly go to tinhte.vn/threads/300021/threads/300012/page-2 as you guessed. However, looking at the response from a request to that url we can see that the page redirects to another url. I used web-sniffer to quickly see the raw response from the server.
The interesting part of the response is this:
<input type="hidden" name="redirect" value="/threads/300021/page-2"/>
The browser will react to this and navigate to the specified URL. Hence the observed behaviour.
Read more about redirects here.

Strange google result listing, invalid URL created

Would be great if you guys could shed some light on this, has baffled me:
I was asked by a client if I could try and make the search term for his comedy night "sketchercise" put his website top of the Google ranking. I simply changed the title tag of the header for the whole site from "Allnutt and Simpson" to "Allnutt and Simpson - Sketchercise # Ginglik - Sketch Duo". It did the trick and now the site comes up top of the Google listing when typing in "sketchercise". However, it gives off this very strange link:
http://www.allnuttandsimpson.com/index.php/videos/
This is the link to the google search result too:
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=sketchercise
This link is invalid, it doesn't make any sense. I guess it has something to do with the use of hash tags and the AJAX driven site, but before I changed the title tag, it linked to the site fine using the # tags. What is the deal with this slash?
The strangest part is that the valid URL for the videos page on that site is /index.php#vidspics, I have never used the word "videos" in a url!
If anyone can explain the cause of this or just help me stop it from happening, I'd be very grateful. I realise that this is an SEO question and I hate that stuff generally, but I hope you can see this is a bit of a strange case!
Just to compare, if you google "allnutt and simpson" it works just fine links to the site and all of it's pages absolutely fine as .php pages (and then my JS converts them to hash tags to keep things clean)
It's because there must be a folder called 'videos' under your hosted files, use an FTP client and check this.
Google crawls every folder and file unless you tell him not to do this, look for robot.txt files to learn how to avoid indexation.
Also ask google to remove that result when you solve this.
Finally that behaviour is not related with hash tags, these are just references to javascript in order to display the appropiate content in you webpage.
Not sure why its posted like this but the only way to stop that page from appearing is using a google webmaster account for this website and make sure the crawlers can't find this link anymore. The alternative is have the site admin put this tag, <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> , in the header when isset($_REQUEST(videos)) is true.
The slash in the address is the parsed form of www.allnuttandsimpson.com/index.php?=videos. You can have the web server change all the php parameters into slashes to make the links look pretty.
Best option for correct results is to create a sitemap and submit it to https://www.google.com/webmasters/tools/ for that site. You will need access.
Oh forgot, the sitemap will make google see all the pages you want it to post, use this for the major pages like those in the main menu. To remove links you don't want requires a robots.txt in the main directory of the site.

ASP.NET MVC Update Address Bar With Ajax Link

I'm trying to create an ajax-driven gallery where each photo in a sequence is loaded with an Ajax.Actionlink.
The user can get to any given photo by passing a parameter to the action method, eg: Gallery/Index?photo=100
The problem is that when the user is cycling through photos with the Ajax.Actionlink's the URL is no longer being updated (the way it would be during normal post-backs) so they can't copy paste from the address bar to get back to a photo.
My question is: what is the best way to solve this issue in ASP.NET MVC? One thing I was thinking of was updating the address bar with hashtags, but frankly I don't know if this is a good approach.
I could use some best-practice advice on how to solve this problem. Any suggestions would be much appreciated, thank you.
If you really want to update the address bar with each ajax update there are a couple of jquery / javascript libraries you can use as described in this blog post: http://stephenwalther.com/archive/2010/04/08/jquery-asp-net-and-browser-history
However, the best practice solution is usually not to try and fake something like this (its only going to go wrong). If you want to give your users the ability to share or link to a photo is to provide a field with the appropriate url or permalink to the url that they can copy from. Google maps has a good example of this - if you wanted to share a map with someone else.
I would look into rewriting your routes to include the photo ID in the path.
E.g., /Gallery/Index/100 instead of ?photo=100. This would be why your ActionLink methods aren't working how they should, as the querystring isn't part of the route.

Resources