Grid view row command in asp.net? - asp.net

In web application, in asp.net i am using one grid view, in that i have one link button, in row command event i am binding the url to that link, when i am clicking on that it is logging out, it is coming to login page. In row command i am writing the code like this
Response.Redirect(s, false);
where s containt the url like abc/abc_approval/xyz.aspx. it is giving particularly that url only remaing urls redirecting to their destinations.
when it comes to login page the url like this
Login.aspx?ReturnUrl=%2fabc%2fabc_Approval%2fxyz.aspx
help me please.

This does not seem the problem of redirect, you may have authentication failed on abc/abc_approval/xyz.aspx or any error could cause the redirect to login page. In web.config check the customErrors tag, Login page might be the default for unhandled errors. Put debugger on the suspected page to see if any error occurs.

Related

Route to /login and /{PageName} in an asp.net app not working

In an ASP.NET Blazor App with Identity I have a page with the page routing
#page "/{PageName}"
When I change the page routing of the login page in Areas/Identity/Pages/Login.cshtml to
#page "/login"
and enter the URL 'localhost:44397/login', the login page shows up as expected.
However, if I follow the link in header bar that I have adapted in LoginDisplay.razor to Log in, the URL changes to 'localhost:44397/login' as expected, but the login page does not appear. Instead, the above page is rendered, where the PageName parameter is set to 'login'.
Endpoint routing obviously works if the URL is entered manually but fails when clicking a link, as if half of the routing middleware would have been bypassed. I tested this with a fresh Blazor template and have no more ideas where to look for the bug.
Accoring to this article, a click on a hyperlink in a Blazor component is intercepted automatically. While the URL in the browser is updated, the request is not sent to the browser but the page is renderd by Blazor. In my case, Blazor can find a suitable page (the one with the #page "/{PageName}" directive) and renders it.
To force loading of the page, NavigationManager can be used:
Login
The href is necessary to render the link with the typical layout. It's probably not the most elegant solution but at least it works.

IIS URL Rewrite breaking Postbackurl to other domain on form button

We have a site which consists of 4 pages in this order of flow:
Default.aspx
List.aspx
SubmitForm.aspx
Thankyou.aspx
We use IIS URL Rewrite module to use a PURL for the landing (default) page. So this:
www.example.com/Chris123
is really this:
www.example.com/default.aspx?UID=Chris123
On the SubmitForm.aspx we have the submit button with a PostBackURL value which sends the form data to SalesForce.com's servers, captures the data, then redirects back to our Thankyou.aspx page.
Is the past, we haven't used the URL Rewrite module and the SalesForce submission has worked just fine. Now, however, with the URL Rewrite rules enabled, when the user clicks the button instead of going to the SalesForce server it redirects back to the form page, clears out the fields and fires all the form validation. This basically just causes a loop of form submit/redirect/form submit/redirect...
If I go into IIS and disable the User-Friendly URL rule (used only for the Default.aspx page) the form submits as expected to SalesForce. Turn it back on and the form submits to itself again.
I don't have a ton of experience with the URL Rewrite -- just basic User Friendly type scenarios. Any suggestions on where to poke around first would be appreciated.
We are running Windows Web Server 2008, app is .NET 4 web forms.
Ok, figured it out.
The issue ended up being that the WebResource.axd was getting caught by the URL Rewrite. Fixed it by adding this to the rule:
<!-- The following condition prevents rule from rewriting requests to .axd files -->
<add input="{URL}" negate="true" pattern="\.axd$" />
I'd read about that earlier but didn't think it was my issue since the PostBackURL was going off to another server. But I guess it makes sense since the PostBackURL needs the Javascript to redirect the post. rOnly reason I caught it was because my log file was capturing "WebResource.axd" as my PURL value with the form as the Referrer.
Here is the page where I found the actual code (at the end) which fixed my issue:
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms

url has /errorpath

I have an issue when I try to access an ASPX page. This aspx page has nothing but the page attribute with codeFile and inherits. Its corresponding aspx.cs file has the code that writes to the aspx file. Everything works fine in my Dev enviornment. When I try to deploy the same in test server and access the page by clicking an hyperlink, I get the foll url
http://tb..hosting.net/review/Search.aspx?aspxerrorpath=/review/Create-xml-writer.aspx
and lands in search.aspx instead of Create-xml-writer.aspx
But the url should be,
http://tb.hosting.net/review/Create-xml-writer.aspx
I did a couple of build and deployed. Still i get the same issue. What does this errorpath=/ mean?
The errorpath part is something that gets passed into a custom error page when an error occurs in ASP.Net, it contains the path of the page that has the problem.
Is search.aspx defined as a custom error page in your web.config file? Turn custom errors off in your web.config file and you should see the actual error message.

Session variable trounced by Chrome and FF

In my asp.net web application on page load I grab the current page url and store it in a session variable to track which page the user is on so they can return to it if they enter an admin area, do some navigating around etc. They can then click the return button and will be taken to the page they were on before entering the admin.
This all works in IE8; however in FF and Chrome when in the admin the return link redirects to the custom 404 page I have for the web app.
For testing purposes I added the code I wrote below in with my page load event:
Response.Write((string)Session["navurl"]);// displays "http://somedomain.com/customerror/default.aspx"
Session["navurl"] = currentUrl;//ex. currentUrl = "http://somedomain.com/contact/"
Response.Write((string)Session["navurl"]);//ex. currentUrl = "http://somedomain.com/contact/"
Again this works without a problem in IE, but in FF and Chrome on page load the session variable displays the 404 page link and after setting it displays the correct link. I used fiddler to see what was going on and Chrome is throwing a 404 in the GET header for the favicon.ico file, which I am not using in this web app.
I added the faviocon file and the link in the head of the site.master file and Chrome and FF now work fine; I'm still not sure why this is happening. Anyone have an ideas why or how my Session variable is getting overwritten by Chrome or FF?
As a side note I have stepped thru the process debugging and currentUrl is the proper url.
Well, if you are using the .NET handler to serve all pages (ie. all file extensions), then it makes sense that when your browser will make a request for favicon.ico (google to understand what this is), the server fails to find it, and it redirects to a 404. Which in turn modifies the Session variable as "the last page served" : 404.
Now when you render you admin page, and query the Session for "the last page served" what do you get ? "404".
I'd suggest checking the URL to see if it reffers to a user-navigationable page before storing it in session
if (IsAUserPage(currentUrl)
Session["navurl"] = currentUrl;
When you access your admin, are you preserving your session? Using Fiddler have you seen another request for your page? Look for image tags with src="", or iframes.
You must set the Session var on every front end page, but, you never must never set it on the admin pages, only getting to build the "Back" link. If you are using Global.asax events, take care to avoid change the var when serving admin pages.

how to force to default.aspx instead of www.domain.com

OK. I'm having a ridiculous problem. I'm trying to use URL rewrite to redirection from www.domain.com to www.domain.com/default.aspx.
I thought by setting default.aspx as the default document it would automatically drop the user there. But for some reason it still comes up www.domain.com.
The reason I want it to go to www.domain.com/default.aspx is that the login control on the page doesn't seem to want to work when it is just the www.domain.com. But of course if I type in the www.domain.com/default.aspx then the login works fine. The login control doesnt seem to post at all if it is www.domain.com. Anyway, I'm trying to avoid troubleshooting why the login control is not firing and just force it to land on default.aspx anytime someone tries to go to www.domain.com. I'm using IIS7. Any ideas here?
You could add something like this to your Default.aspx code behind (in your Page_Load method):
if (Request.Url.LocalPath == "/")
{
Response.Redirect("~/Default.aspx");
}
Note that the default document setting normally allows that page to be displayed under www.domain.com/ and www.domain.com/default.aspx (it doesn't do any redirecting for you).
The anwer has to do with a breaking change in ASP.NET 4. Answer was that the form action was empty action="" when on extensionless root url. but if on that same page, but had the name of the page in the url (blahblah.com/default.aspx) the action gets filled in. the easy fix for me was to put Me.Form.Action = "Default.aspx" on the page load of the home page. problem fixed.

Resources