Create a Fixed URL - asp.net

I have a web application that have many pages and folders, I want to make the URL to this website fixed for all pages, example: if the web site is
www.testwebsite.com/home.aspx when I redirect to login.aspx (for example) I want the URL to be
www.testwebsite.com/home.aspx without any changes and so on
Any suggestions ?

You can do a Server.Transfer, instead of Response.Redirect from home.aspx to login.aspx. This will keep the url as home.aspx
Response.Redirect : Tells the browser to go and visit another url. So there is a response coming back to browser and then browser is navigating to the new page. So its like a new request now. You will see the new page url in your address bar.
Server.Transfer : there will not be any "Redirect" response coming back to browser. The Server itself change the destination page. So the client browser does not know that its another page. So the url will not be changed.The Transfer method preserves the QueryString and Form collections.

Related

Form Data Not Posting While Using URL Rewrite

OK. Where to start....
I have a website. It is running on an IIS server using classic asp. I have forms on that website.
The forms were working fine until I decided to add some url rewrite rules to my web.config file to redirect nice looking urls.
After doing that, the form on my website does not post the data. It is going to the correct address, but nothing is passing to the page that is suppose to do the processing. On the page that I am processing if I do this:
For each FieldName in Request.Form
Response.write FieldName & " = " & Request.Form(FieldName) & "<br>"
Next
I get absolutely nothing. No form field names or values.
What do I need to add to the web.config file so that the data will post? And... more importantly... Where do I need to add it at in my web.config file?
Here is a text copy of my web.config file http://elvis-is-alive.com/webconfig.txt
Your web.config contains action=redirect.
A redirect always results redirect header being sent to the browser. This changes the URL in the browser address bar, and the browser then issues an HTTP GET for the new address. With an HTTP GET, no form/post data are ever sent; all arguments are assumed to be in the URL querystring.
If you'd like to avoid the redirect and use a true rewrite, change your web.config to use action=rewrite. Using this method, no redirect header is sent back to the browser, the browser address bar never changes, and IIS simply redirects the current request stream to a different location.
Something tells me that's not what you want-- you want the address bar in the browser to change and you want the form/post data to be preserved. This is not possible unless you do something very unusual, e.g. render a temporary interstitial page containing the original form/post request with an action pointing at the new URL. I don't recommend doing this.
Why not just change the form action in the original page's HTML?

Document.referrer empty when navigating from external url?

I have the following code:
var previousPageUrl= document.referrer;
alert(previousPageUrl);
This will not work if the previous page url is of any external site, i.e., not of my application.
For example:
If I am in Page 1 and went to Page 2 of my application then I will get page 1 url in referrer in Page 2 load but when I go to external site say www.google.com then again when I come back to page 1 the I will not get www.google.com as referrer url.
Can Somebody tell to resove this issue.
Generally, Referer URLs are passed between unrelated sites when navigation occurs due to a link click or JavaScript-based navigation. Referer URLs are NOT sent if the user uses the browser's chrome (e.g. address bar, back/forward buttons/etc) to navigate.
For security/privacy reasons, the Referer URL is stripped out when navigating from a HTTPS site to a HTTP site (e.g. from https://google.com to http://example.com). It can also be deliberately stripped out via a variety of JavaScript and HTML tricks. There is no way to disable this behavior to get the Referer URL if it has been stripped.

Direct linking to a gov.uk ASP page (possibly user session related)

I am unfamiliar with ASP but I need to link directly to a page on the http://carfueldata.direct.gov.uk/ website which I assume from the .aspx extension is built in it. My problem is that when a user first clicks on the link, the destination page immediately redirects them to the home page, presumably because there is some kind of user session required (?), I do not know. Not a good user experience for my visitors. The second time you follow the link it displays happily. The chances of my users following a link twice is slim.
Is there a standard URL parameter or something that I can append to tell the ASP platform to generate a user session and not redirect.
To see problem for yourself open this link in a new window, then close it, and repeat. First time it will redirect to home page. Second time does not: http://carfueldata.direct.gov.uk/search-new-or-used-cars.aspx?vid=30392
It looks like they are using session for this purpose. As far as I know there isn't any way to override this.
But you can do some work around for this.
Call jQuery ajax function to homepage and redirect on its complete event.
While calling the ajax function the cookie (ie session set) will be set on client's browser and after the ajax call redirect user to the page.( The page that won't allow users to visit directly)
Click to go
function LinkClick()
{
$.ajax({
type: "get",
url: "http://carfueldata.direct.gov.uk",
dataType: 'jsonp',
complete: function (msg) {
window.location.href=" http://carfueldata.direct.gov.uk/search-new-or-used-cars.aspx?vid=30392";
}
});
return false;
}
When you initially submit the request to the website, you receive a 302 status (moved (temporarily)) and a redirect to the home page. This is because there is no session ID cookie in your request. The redirect response from the server creates the session ID cookie for you and from then on, the site honours subsequent requests.
I don't know which client library you are using, but it should be possible to intercept the redirect request sent by the server, and replace the redirect URL to the homepage with your original request URL. Since the redirect response contains the session ID cookie, we can assume that the session has been created and your original request should work immediately without the redundant visit to the home page.

Hyperlink url contains localhost and port number

I am creating a searching website using ASP.NET .On my one page I show URL of results.When I click on URL a new link is open but the URL path for the new link in the browser include loalhost:portnumbet.I do not want this in my URL.
For eg.
result
so on clicking result I go to browser where the URL is "https://localhost:8080//www.google.com"
why this localhost:8080 includes in the URL.
Thanks
When you are redirecting to the URL, you will not be adding any protocol information, so it will default to the current website/protocol.
For example;
Response.Redirect("www.google.com")
is not the same as;
Response.Redirect("http://www.google.com")
You need to add the fully qualified URL, otherwise it will believe it to berelative to the current website, therefore add the http(s):// to the redirect.

Response.Redirect ReturnUrl

I'm trying to use Response.Redirect on an ASP.NET page that uses routing and membership -- in order to redirect non logged in users to the main page. This is a page that should sometimes be viewable to anonymous users based on content. When I redirect to the login page, the browser fills the returnurl with invalid content.
The question is how do I remove the ReturnURL before sending the user "off"? Or how do I fix it so that it includes the proper link?
The page is in a different directory. It redirects properly but sets the ReturnURL to an invalid path.
The ReturnUrl is just set to the folder. Not to the page with query params nor do the route.
UPDATE
Okay where is what it is doing
I have a folder Actions. I'm redirecting to Login.aspx. It redirects to login.aspx but then sets the returnurl to Actions/Login.aspx which is absolutely wrong.
It is wrong on 2 accounts:
The login.aspx doens't exist in the actions folder
It creates a recursive redirect
Update Fixed Partially
Okay, it was because I was in a different folder and not redirecting to the proper page.
I had "login.aspx" instead of "../login.aspx"
However, it is not setting the returnurl to the routed path. It is stripping the returnurl. I may have decided to do this as a design decision though, not 100% sure.
I have not understood the nitty gritty of the issue you are facing, but I guess you might have missed to apply Server.UrlEncode to return url. Please have a look at what Server.UrlEncode does at
http://msdn.microsoft.com/en-us/library/ms525738(v=vs.90).aspx
Below is the piece of code which shows how specify Return Url using Server.UrlEncode
Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" +
Server.UrlEncode(Request.Url.ToString()))

Resources