In my ASP.NET Website, I am trying to use Server.Transfer to redirect client to different url(all pages resides in same domain) instead of using Response.Redirect because of performance issue and heavy flickering. But when I use Server.Transfer, all session values are wiped out and getting NullReference error even though if I enable page level EnableSessionState. After several attempt, i tried Context.ReWritepath just to change the url and lost all masterpage contents like menus, headers. Any idea? Any help? Am i doing anything wrong?
This technique is great for wizard-style input forms split over multiple pages. But there's another thing you'll want to watch out for when using the preserveForm parameter. ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer the form and query string values. You'll find this documented at
Q316920
The unofficial solution is to set the enableViewStateMac property to True on the page you'll be transferring to, then set it back to False. This records that you want a definitive False value for this property and resolves the bug.
Read More here
Related
I am trying to make this feature, and I'm really stuck.
I have two applications that run on the same domain. and I need to have one application load pages from the other one inside it's own (the first) master page.
I have full control of the code of both sides, of course.
I have tries using HTTPRequest, and HTTPResponse, and I have tried using WebBrowser. Both work great as long as I have static(plain HTML) pages. However,
those pages are actually dynamic. the user need to press server-side buttons (postback) and generally use the session, viewstate, and/or cookies.
because of that, HTTPRequest and WebBrowser fail me, as they do not cause postback, and therefore those server-side controls are not working. more so, if I try to "fake" a postback by saving the ViewState after each response and than resend it on the next request, after a few (3-4) times the original page will return a "The state information is invalid for this page and might be corrupted" error, even if I use
EnableViewStateMac ="false" EnableSessionState="True" EnableEventValidation ="false" ValidateRequest ="false" ViewStateEncryptionMode ="Never
So... any ideas how can I solve this issue?
Thanks in advance
What is the main desire here?
Wrap one site's content in another without any architecture changes?
ANSWER: Iframe
Have a single submit button submit from two sites?
ANSWER: Not a good idea. You might be able to kludge this by creating a scraper and parser, but it would only be cool as an "I can do it trophy". Better to rearchitect the solution. But assuming you really want to do this, you will have to parse the result from the embedded site and redirect the submit to the new site. That site will then take the values and submit the form to the first site and wait for the result, which it will scrape to give a response to the user. It is actually quite a bit more complex, as you have to parse the HTML DOM (easier if all of the HTML is XHTML compliant, of course) to figure out what to intercept.
Caveat: Any changes to the embedded site can blow up your code, so the persons who maintain the first site must be aware of this artificially created dependency so they don't change anything that might cause problems. Ouch, that sounds brittle! ;-)
Other?
If using an iFrame does not work, then I would look at the business problem and draw up an ideal architecture to solve it, which might mean making the functionality of the embedded site available via a web service for the second site.
I'm setting up an SMS service where I have to post some values,
like receiver, sender and message to a specific url at provider.
Pretty simple if I just add a button and in the button event I
make a response.redirect("...url and url parameters with values...")
But I don't want the user to be redirected to another page when the
button is clicked. I have tried to post the url to a new window with
JavaScript. This is okay, but I'm running into a lot of pop-up blocking issues with
the browser...
Is there any recomendations on how to accomplish that, I think it must
be a pretty common way to post information to payment services and such.
Best regards.
When you need to load content in to different pages without reloading you can use local storage which is now widely supported. Similar in a sense to cookies but much more flexible and up to date.
In depth look in to Local Storage here
Brief local storage demo here
I can't be sure the exact method of using this with VB or C# but I am sure if you look around you will find it. It is a little hard to tell your exact use case, but ultimately GET variables are loaded in to the page or script on load, s even if you manage to change or update the variable, that won't be accessed until next reload.
With System.Net.WebClient you can call a website without doing a redirect.
Dim result As String = New System.Net.WebClient().DownloadString("http://...")
I have seen this on some survey websites. What is the C# code they use on the client side to keep the URL same, but when clicking the "Next" button, the same aspx page is maintained
without having any query string;
without any change even a character in the url; and
the grid, the data , the content, the questions keep changing?
Can anyone give a code-wise example how to achieve this?
My main query is how is this done in code-behind to change data of page and maintain same url.
Nothing simpler that a session, maintainted at the server side. Store a "current question number" in session, increment it at each succesfull postback and you have what you ask about.
Another possibility - a cookie which contains "current question number".
Both cookie and session are invisible in the query string of course.
"change data of page and maintain same url." Answer is Server.Transfer.
This method will preserve url.
The Next button may submit a form using the HTTP POST method. The form data may contain the session, question and response data. The site uses that to build a new response. Unlike a GET, a POST does not incorporate data into the URL.
Developers will typically accomplish this task by using AJAX. The basic premise behind it is that only a certain portion of the page (e.g. a grid or content area) will make a server call and retrieve the results (using Javascript). The effect achieved is that there has not been a full post back, which is why you don't see the URL or parameters changing.
It is possible to do this using jQuery, pure Javascript, or Microsoft's UpdatePanel.
oleksii's comment has some good links as well:
That's the AJAX magic. There are many JQuery plugings for this, for
example this one with a live demo. You can also program it easily
using JQuery Get or Post or any other wrapper that use XmlHttpRequest
object.
While redirecting from page to page generally i used to pass values as querystring but as you know query string is not a good approach as there are many security concerns and more over its having a maximum size is of 256 Bytes or ie length 2048 characters. So is it a good approach to access variables by setting previous page ie "<%# PreviousPageType VirtualPath="" %>" and accessing previous page items
Please let me know, is there any other way for passing variables other than Sessions and is using Previous page concept a Good Approach?
Here is from MSDN's How to: Pass Values Between ASP.NET Web Pages:
You can pass information between pages in various ways, some of which
depend on how the redirection occurs. The following options are
available even if the source page is in a different ASP.NET Web
application from the target page, or if the source page is not an
ASP.NET Web page:
Use a query string.
Get HTTP POST information from the source page.
The following options are available only when the source and target
pages are in the same ASP.NET Web application.
Use session state.
Create public properties in the source page and access the property values in the target page.
Get control information in the target page from controls in the source page.
So assuming you have the same ASP.NET application PreviousPage property is what exactly was designed for your case.
PreviousPage is intended for use with cross-page postbacks. If that's what you're doing, then there's nothing wrong with it.
Without a postback, a reference to an instance of the previous page class won't (shouldn't) contain any state information.
If you're just using a link from one page to another, it's better to use something like session state, cookies, or your database. If you're doing a redirect, there are a few more options (including the use of Server.Transfer() instead of doing an actual redirect).
You can use a alternative approach, you should keep you data in context.items
This approach is very useful to save data in between two or more sequential pages. Its a simple approach used same as:
Context.Items.Add("SOMETHING","somevalue");
* You need to use **Server.Transfer
instead of Response.Redirect. Because if you use Response.Redirect method, your context would be cleared and you cannot get any values.
Hope this will helps you.
my client has a website that currently makes requests on a particular event (click, load etc). the website is working well and all but he has a problem with getting the website statistics with Google Analytics, the reason is, because the website never does a re-direct to a different page, it is all within the same page and no matter what event is loaded in the website(be it a video, tables etc) everything are displayed under the same url
www.somewebsite.com/default.aspx
what I want to achieve is on a particular event, change the url to
www.somewebsite.com/default.aspx?type=abc&id=999
How can I do this,. what is the easiest method to do this? please advise. The whole website is built in C#.
Many Thanks.
Is this event happening on the server or the client?
If it's on the server, you can call Response.Redirect and add your new query string parameter to the current url.
If it's on the client (Javascript), you can set the location property.
If you want to preserve your page's state, try adding your querystring parameter to the form's action parameter in Javascript.
Alternatively, as jeffamaphone suggested, you can change the hash (the part after the # sign) by setting location.hash without posting back to the server.
Actually, you should probably move some of the elements to different pages... this is based on what you said:
because basically all I am doing is
hiding and showing elements based on
events, if i do a response.redirect,
it will reload teh homepage.
If I understand correctly, the user is never redirected to a different page, you are just hiding/unhiding elements from default.aspx based in query strings... correct? the simplest solution will be to split that content into different aspx pages.