Asp.net Url loses page path on postback - c#

Background:
We are redoing our website and trying to modernize it. We were initially experimenting with AngularJS but dropped it due to some of our users being on unsupported browsers. We ended up just doing VB webforms and updating the design and functionality of our site.
I was having an issue with buttons or items that cause a postback. When the page tries to postback it hits to the path but loses everything between the hostname and the last "/"
For example I have a login page set up in the location
/Secure/Account/Login.aspx
I have a route as well that directs from /Secure/Account/Login.
So when you visit the page you are at:
www.website.com/Secure/Accounts/Login
When I click the login button though, instead of posting back, I am directed to:
www.website.com/Login which doesn't exist so I get an error.
This occurs if I navigate to the page instead of using the route as well. So if I am at www.website.com/Secure/Accounts/Login.aspx and click the button, I end up on www.website.com/Login.aspx with an error.
This doesn't affect pages in the root directory as long as they do not use routing attributes. We have some pages that use routing attributes that have the same issue though.
We have page /Category.aspx in the root directory with the route
/Category/{Attribute1}/{Attribute2}/ configured for the page.
If I am on the page www.website.com/Category/Attribute1/Attribute2 when I click on a button that posts back, I end up at www.website.com/Attribute2 with an error.

The issue ended up being a really small piece of code from when we were working with Angular
On our master page .aspx we had included the line:
<base href="/">
Removing this line, which we didn't even need anymore fixed the issue.

Related

Sharepoint 2013 welcome page redirection issue

I am facing a weird issue where I have changed the welcome page of my sharepoint 2013 site to a page called Home.aspx, so now my welcome page link looks like https://abc.sharepoint.com/sites/ThisIsSCName/Home.aspx. When I share the link of the site, to my team as https://abc.sharepoint.com/sites/ThisIsSCName, most of the time it works fine and redirects to Home.aspx, but sometimes it's redirecting to default.aspx, for example, like once or twice in ten times when I load the site, it's redirecting to default.aspx. It's so strange. I tried hard to crack the error, but could not. Help me in this issue!!
Not sure why this is happening. Is it happening to a certain set of users or everyone?
but as a workaround, you can redirect from default.aspx to home page by placing a redirect script in content editor webpart on default page.
function Redirect() {
window.location="http://yourpage.aspx";
}
This will appear as if its redirecting to home everytime.

Asp.net routing between different web forms

I am creating a website and I'm trying to implement routing feature. Most of the time it works fine, but I've found a problem while routing between different web forms placed at different levels from the root of the website.
The above picture shows all the routes defined and picture below shows the solution explorer of my project:
Home page(home.aspx) of my website is shown below:
On clicking the picture it opens a new page(singlepage.aspx) with whole article about the topic and contains the required url(sitename/heading/querystring):
But from there when i click on HOME button, it does not take me to home page, but instead gets me to the url like this:
Seems like it is not calling the "routeHome" route, instead calls "routeSinglePage".
This is how the html for taking us to HOME page is:
So I wanted to know how I can get it to the home page from singlepage.aspx by clicking on HOME button. Do I need to add new routes or something else.
Thanks
Change the HTML to:
<li>Home</li>
<li>About</li>
<li>Contact</li>
The "/" indicates an absolute path, you are currently using a relative path and hence the issue.

ASP.NET 4.0 MAC validation failure

To begin, I should mention that I'm quite new to C# and ASP.NET 4.0. The solution to this problem may be elementary so don't hesitate to ask fundamental questions.
I've inherited an ASP.NET 4.0 application that failed our automated security test because of <page enableViewStateMac="false"> (not my fault). Of course, I turned it on. At that point a very specific pattern of behavior emerged:
1) I can navigate to the application landing page
2) attempting to click on any link leaving the landing page results in a "Validation of viewstate MAC failed..." error.
2a) the exception to this is that clicking on the link that takes me to the landing page (the page I'm already on) works just fine
I should mention that navigation to other ASPs occurs by way of Response.Redirect(...). I can successfully navigate to a page if I enter the url directly into the nav bar (http://dummyhost.com:12345/Enroll.aspx as opposed to http://dummyhost.com:12345/LandingPage.aspx and then clicking on enroll).
In the Page_Init() method of the master page, I'm setting:
Page.ViewStateUserKey = Session.SessionID;
If I comment out this line, I can turn on MAC and the application is perfectly happy. Can anyone illuminate what's going on?
The most likely cause is that some landing-page-specific data is being submitted to the server and persisting through the call to Response.Redirect, so the enrollment page tries to read the landing-page-specific data and fails the request since the data cannot be interpreted correctly.
Instead of using Response.Redirect, consider using ... directly in your markup when you want to generate a simple link. This will cause the browser to make a vanilla HTTP GET request to the specified resource, free of any current-page-specific date.

Browser back button does not work with asp controls

I have a site with few asp:CheckBoxList and asp:DropDownList controls. Checking few options or selecting few items in the dropdowns makes the back button browse to same page just with previous selections. I would like the back button on the browser take the user to the previous website visited. As example: if the last visited site was: default.aspx, then the back button from my current site should go back to default.aspx.
Adding few header options regarding caching only broke the back button to: Page Not Found message.
How can the user browse back to the default.aspx by the first back button clicked on the browser?
Just need to confirm, are u using IE 10 to run the web system?
I had encounter asp control component not working properly when i was using IE 10.
Maybe consider using other browser type like firefox and safari to see if it can work properly

Asp.Net page reload problem after login

I am devolping a web application.the problem is that i am using a login control (not a .NET control) which is a part of master page and is acessible from all pages. if user log In from a page the login control updates itself and displlay some statistics of logged In user but the specific page does not reload. (some options on page are visible only to authenticated users, so that after login, page should be reloaded to display such options)
after logIn methoed I wrote
Reponse.Redirect(Request.Url.AbsoluteUri)
after this the browser response the "Page cannot be displayed"
It would be of great help to me.
Many Thanks, Regards. AZHAR
From you description it is not clear what happens, but with high possibility you get infinite loop, when page is redirected to itself again and again.
Most obvious problem that you place redirect code in Page_Load,
as possible resolution:
Place Reponse.Redirect(Request.Url.AbsoluteUri) to OnLogin event of your login control
if you anyway want use Page_Load, at least add following check:
if(IsPostBack)
Reponse.Redirect(Request.Url.AbsoluteUri)
But last case is very bad style because may have lot of side effects.
Make sure your redirect is not causing a loop. Check Page.IsPostBack
Be aware that POST variables are lost during this operation.
Another thing that you should look at is the roles that you allow in the folder (in the web.config file in the folder).
I accidentally misspelt a role name and it kept redirecting my users to the login page.

Categories

Resources