Unable to redirect page in asp.net - asp.net

I have grid on my asp.net page. grid having 3 columns with hyper links. both links working properly. but one is not redirecting desired page. I tried in different browsers as well . but got different error : as
In Mozilla Firefox :The page isn't redirecting properly
description In Mozilla Firefox :
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept
cookies.
In Google chrome : `This webpage has a redirect loop`
description In Google chrome :
The webpage at http://myserver:425/(S(c0kr2xuftxiwhm25cm4vjg45))/mypage.aspx?type=2&userId=8 has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
since i tried lot of solutions over net , as i tried cleared cookies from browsers, added
<sessionState
cookieless="false" // True also tried
timeout="10">
</sessionState>
in web config file but problem is same there. I checked link is properly redirecting desired page. I mean i checked spelling of my link it is perfect. what else i have to try to resolve it ? where should i am making mistake ?
<ItemTemplate>
Go to my page
</ItemTemplate>

do check anywhere , are you redirecting same page ? I think you need to check each condition throughly , you must be redirecting same page either with same parameter or with different parameters.

Try adding runat="Server" attribute to the link tag, like this:
<ItemTemplate>
<a runat="Server" ID="linkID" href="mypage.aspx?type=2&userId=<%#Eval("userId") %>">Go to my page </a>
</ItemTemplate>

The most obvious place to check is inside mypage.aspx or mypage.aspx.cs for a redirect (see comment by paolo). The problem is not the link from the grid, this is simply a link.
What happens in this case is that you arrive at mypage.aspx, are redirected to mypage.aspx where you are redirected to mypage.aspx, etc.

You can also try this if you have one field in query string. Here in your case you have userid,
<asp:HyperLinkField HeaderText="Your Header"
DataNavigateUrlFields="userId"
DataTextField="Your Data Field to Display"
HeaderStyle-HorizontalAlign="Center"
DataNavigateUrlFormatString="mypage.aspx?type=2&userId={0}"
ItemStyle-Width="35%"
ItemStyle-HorizontalAlign="Left"
/>
In case of multiple
1) DataNavigateUrlFields="userId, employeeId, departmentid"
2) DataNavigateUrlFormatString="mypage.aspx?type=2&userId={0}&employeeId={1}&deptid={2}"
sequence of 1 and 2 must be same.

Related

Page address is correct, but content is not

I have some route table in global.asax as follow:
routes.MapPageRoute("en_term", "en-us/Terms", "~/en_us/Term.aspx");
routes.MapPageRoute("en_about", "en-us/About", "~/en_us/AboutApp.aspx");
routes.MapPageRoute("en_comm", "en-us/Community/Feedback", "~/en_us/Community/Feedback.aspx");
and also have a link:
<asp:HyperLink ID="footerContactLink" runat="server" NavigateUrl="<%$RouteUrl:routename=en_comm%>" Text="Feedback"/>
when i click on this link, page navigate to http://localhost:1384/en-us/Community/Feedback
but contents of the page belong to another page (Term.aspx)
I don't know whats happening and can't fix the problem.
Just a dumb dumb obvious one: is it possible that Feedback.aspx contains the same content as Term.aspx?

Code target issue

I have a website that sits at http://www.mockcourt.org.uk/mcc/default.aspx this works fine when I'. pointing to it at the address.
However the mcc folder is a secure folder and to make it secure the address is https://secure17.prositehosting.co.uk/mcc/default.aspx but when I point to this it does not work.
The problem is a line of code that I'm using in default.aspx and that is
</asp:DropDownList><asp:AccessDataSource ID="School_DS" runat="server" DataFile="~/App_Data/MockCourt_db.mdb"
I believe that the </asp:DropDownList><asp:AccessDataSource ID="School_DS" runat="server" DataFile="~/App_Data/MockCourt_db.mdb" is saying that the database is at this location but now that I have moved to secure17.prositehosting.co.uk instead of www.mockcourt.org.uk this is no longer valid.
Does anyone know what I should change the code to so it points to http://www.mockcourt.org.uk/App_Data/MockCourt.db
Use an absolute URL to the data file?
</asp:DropDownList><asp:AccessDataSource ID="School_DS" runat="server" DataFile="http://www.mockcourt.org.uk/App_Data/MockCourt.mdb"

Some user controls not loading when the 'Back' button is pressed

I'm working with ASP.NET and VB.NET.
I have a page which contains 5 user controls.
The page itself does nothing, it just presents the user controls to the user.
The user controls work fine when I come on the page, or when I refresh, but when I go to another page, and press 'Back' only two of my user controls shows up, and they don't work like they're supposed to!
Short description of the controls:
2 controls which look if the user has to create something and shows an option to do so. (goes to the DB)
2 controls show an overview if needed (goes to the DB)
1 control looks if the user is an admin (does not go to the DB, but looks in the securityContext)
So what happens is:
the first 3 controls don't show up
1 control shows his default state (although depending on the user it shouldn't)
the admin control always shows the admin link, even if the user isn't an admin
I've tried looking at caching (disabling, enabling), I've tried cheating the viewstate, I've tried using a placeholder, page_init, ..
Nothing seems to work though, and I'd like this to actually work, 'cause I'm pretty sure users will do this a lot. When I refresh everything works like it should again, because the server gets contacted again..
What should I do? :/
Some code:
<pm:MenuA ID="MenuA" runat="server" />
<pmm:MultiStepMenuA ID="MultiStepMenuA" runat="server" />
<rm:MenuB ID="MenuB" runat="server" />
<mm:MenuC ID="MenuC" runat="server" />
<br />
<am:AdminMenu ID="AdminMenu" runat="server" />
IMPORTANT UPDATE: I don't have this problem with Firefox, only IE9 :/
Blame internet explorer..
Apparently it kept on using an older version of my website "to improve speeds". I removed my history, and I unchecked the "Preserve favorite website data".
After that it worked. The older page was gone, and it was replaced by a newer version.
Thanks anyway, I hope this can help somebody else!
The easiest solution for this problem is to add the following directive at the top of the page to prevent IE or IIS from caching this page:
<%# OutputCache location="None" %>
You can apply this setting globally to all pages by adding the following to the system.web portion of your web.config:
<caching>
<outputCache enableOutputCache="false" enableFragmentCache="false" omitVaryStar="true" />
</caching>

Form Post Error

Can anyone explain what might be causing this error. Im thinking its the quotes.
Exception Details: System.Web.HttpRequestValidationException: A potentially
dangerousRequest.Form value was detected from the client
(ctl00$ContentPlaceHolder1$DetailsView1$txtContent="...l economy.<br /><br />The
Prop...").
The contents of a control (probably a textbox) contains what ASP.net considers to be markup, eg:
<br /><br />
You can add ValidateRequest="false" to the Page directive in your .aspx file as follows:
<%# Page ........ ValidateRequest="false" ........ %>
As other answers noted, asp.net is doing this to try and protect you from potentially malicious input so make sure you're aware of the risk and encode/decode user data appropriately.
I think you can take a look at this A potentially dangerous Request.Form value was detected
Its the html "<br/>" tags.
Here's an article with a brief explanation . Also shows you how to work around it by turning off validation. Though I guess that would be a bit dangerous to just turn it off.
It actually should be
<br /><br />
it complains about.
That would be the '<' and '>'.
EDIT: It's assumed that including html entries in form responses is intended as an attack on the server on which the form resides. So, by default, any code that resembles html (i.e. includes '<' or '>') is automatically flagged as a problem.
One way to resolve this is to turn off this type of validation by setting validateRequest="false" in the Page directive for that page, but there are other (and better) ways to work around that.
Here's some information from Microsoft about this issue.
My idea: allow this exception to be thrown. Use Application_Error handler to write code, that redirects (using Response.Redirect - this is important, since this gives users’ browser ability to go back) user to a custom error page. On this page write some text explaining that users had incorrectly input some text. Something like:
"Dear user, you have entered some invalid text, like “<” or “.”. Please, enter text using only characters and numbers".
Put a link on that page, and this link can contain a javascript "back" command:
href="javascript: history.go(-1)"
Users after clicking suchlink will be redirected by their browsers to the previous page, where they can re-edit their input.

ASP.NET button click event not working in IE

in my asp.net page, The asp.net button click is not getting fired in IE,But in mozilla its working fine. Any thoughts ?
I've had a similar problem when using a non runat="server" form nested inside a runat="server" form or vice versa, like so:
<form runat="server">
.... Some code
<form method="post" action="somepage.aspx">
</form>
.... Some more code and a button
</form>
The first form seems to get closed when the inner form is closed so any buttons after the closing tag of the second form don't postback
Javascript error specific to IE is my guess. Do you get the "error on page" message in IE?
It could be a security settings problem. It maybe that your settings do not allow javascript to run from sites in the "internet zone". Try adding your site to "trusted sites", then refresh the browser, and try again.
I'd also check for malformed HTML or any additional script that might interfere or intercept the postback unreliably.

Resources