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.
Related
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.
When I navigate through my Website and access a new Site, by example:
Default.aspx
it would show in the URL-Bar: www.mySite.com/Default.aspx
But I want to hide this! -> So each time, it should stay: www.mySite.com
How to achieve this?
You could have a look at routing. Routing will enable you to add a path like www.mySite.com to a specific aspx file.
It's quit easy to setup in your global.asax :) You can check the following url for some info ASP.NET routing
If you want every page to have your main domain name only in the url, you could create a frame in your index page (f.ex. Default.aspx, or even better index.html):
<frameset>
<frame src="default2.aspx">
</frameset>
and then create your new startpage in default2.aspx.
However, frames have disadvantages, and your visitors wouldn't be able to copy the url - they would always return to your startpage.
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.
I have a form on a masterpage which is very simple but will not work when the site is at the root.
Works fine:
www.mysite.com/page.aspx
www.mysite.com/another/page.aspx
Does not work:
www.mysite.com
I click the button and it postsback to
www.mysite.com/default.aspx
But nothing has executed, now if I try the form again on /default.aspx it will postback and execute fine.
What am I doing wrong?
It sounds to me like the default page redirection is either accidentally (or intentionally) losing all form data. I would first suggest not redirecting to a page that doesn't exist.
However, if you insist, I'd try something like URL rewriting. Hopefully a rewrite from a module will keep the form data intact, but I can't say for sure it will. Good luck!
Thanks for the reply, I just figured it out!
I am using isapi to make sure my urls are all lower case, and 301 redirecting any upper case URL's to their equivalant lowercase version.
On postback its action is Default.aspx ... My script was redirecting it to default.aspx and loosing the values before it was posted back.. DOH!
Do you have an Index.aspx at the root of your site?
I've inherited an ASP.NET application that contains a login screen. When you first start up, or you haven't done anything for a while, it comes up. It turns out we don't need this extra layer of security, and I'm trying to remove it. I thought I removed the code that was doing the redirecting, but it's still going to the login page, even though I've told the app to use default.aspx as the start page, and ensured that default.aspx contains no code that should trigger the redirect (it's using a master page, but the master page also contains nothing that should be redirecting). Where else might it be redirecting to the login page?
Look for <authentication> sections (should be under <location> sections) in your web config and delete them
Sounds like it could be forms authentication in effect.
In the web.config file change the authentication mode value to none and see if that makes a difference.
<authentication mode="none" />
Found the problem. Even though I thought I had all the redirect code removed, there was still some buried in a user control on the default page. Removing that allowed me to bypass the login screen. So, I can't mark any of the responses as the answer, but I gave them all up votes as they were all good answers.