giving an alert after a successful sign up in asp.net - asp.net

I want to give an alert after person sign up successfully. And then I redirect it to index page I tried something like that
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Login is successful!" + "');", true);
Response.Redirect("index.html");
But alert cannot be seen.

Use a cookie. On successful login add a cookie in response, containing a greeting text, and on the landing page - check with javascript if the cookie exists, and if yes - show the alert, and delete the cookie. This way you can personalize the alert message with user's name for instance.

This won't work -- you're registering a startup script to the current page, but then redirecting to a different page. So the page with your script never gets sent back to the client.
You could try one of two approaches instead:
Register the script after the redirect (of course the redirect target would have to be an aspx file, not html for this to work).
Add another line to the startup script that performs the redirect on the client side. (ie, using window.location = index.html after the alert)

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?

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.

automatically redirect user to login page using error code

I have several web services that are being called using AJAX requests from Asp.Net page. If the user's authorization fails, i want to redirect him to the login page.
The problem i am facing is i have to manually redirect the user in the errorHandler function of AJAX request.
I was wondering if there is a way i can throw HttpException with proper error code from my webserivce (i dont know which) so that browser understands the response and redirects user to the login page?
I tried throw new HttpException(401,"Unauthorized access request); in my service call, but my errorHandler handles this exception and browser doesnt redirect user back to login page.
Also i was thinking if i can achieve this using HttpModule, will that be a better solution rather than having Authorization check in the service constructor?
--Update--
After adding HttpContext.Current.Response.RedirectLocation = "login.aspx"; and HttpContext.Current.Response.StatusCode = 307;, it now gives me an error saying "Resource cannot be found". This is what it shows in the RequestedURL: /Web/Services/svcSomething.asmx/login.aspx.
How do i tell browser that redirect location is a new page and not the webmethod?
IMO - you need to handle the error (401) on the server side & redirect the user to the login page. Since you don't have any handler on the server side, the error is passed on to the client as a response & so you are seeing the code on the client-side to redirect the user...

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()))

What is a valid use for Response.Redirect("SomeURL", false)?

In ASP.NET I frequently use Response.Redirect to redirect the end user to another page on my system. I always set the second parameter to true to immediately end the response.
For the life of me, I can't think of a reason why anybody would ever set that parameter to false. What's the point of continuing generating a page when the end user's browser is just going to be redirected to a different page immediately?
Response.Redirect does not mean that The Page-lifecycle has ended on the server, it just sends a header to the client.
Perhaps you want to redirect the user first and THEN save his large amount of uploaded data to the database?
HttpServerUtility.Transfer by the way does terminate the Page-lifecycle, but it does not send a header, it simply serves a different page.
Response.Redirect(..., true);
client will be sent the redirect for the new page, processing will stop as a thread abort will occur
Response.Redirect(..., false);
client will be sent the redirect for the new page, current page will be allowed to continue processing, perhaps some cleanup work to do or something else
client will never see the results from current page in either cases
Why not. May be you have some things to complete on this page before the processes of a page will be killed. Writing to file and then colsing it for example. Or making some changes in DB, with proper ending of connection.
Response.Rediect("any page like Default.aspx");
When the control reach on this statement our page will be jump to the page that is specified into the brackets. The page may be .aspx, .asp.htm etc...

Resources