I'm new at ASP, and I'm trying to code with a simple tree to organize my code. It is as follows:
-act
connect.asp
login.asp
-db
database.sql
-img
images.files
-style
styles.css
-view
index.asp
For now, on training's sake, my index.asp is a login page, that calls login.asp to actually login the user. Then, that login.asp redirects him back to Index.asp. I am calling the login.asp just fine from my index.asp, because I use HTML to reference it:
<form action="act/login.asp" method="post">
But I can't call index.asp from my login.asp. I have tried
response.redirect(Server.MapPath("../index.asp"))
But as I read about MapPath, it does not accept ../ and when I just Server.MapPath("/") it references the current folder.
How can I navigate through my folders using ASP? I have nothing accept MapPath and it does't work with parent folders.
When you use MapPath it returns a local physical path, and redirect("url") wants a URL to redirect you to. Now, ../ does not work in ASP. So, what you can do is:
responde.redirect("/parentdirectory/index.asp")
Note that If you use the same code only with "/index.asp" it won't work, since "/" brings you to the root of the project.
Related
I have a subfolder in the web site (ASP.Net) named "wcms" which contains several files including "login.aspx" and "index.aspx". the login page checks the username and password and redirect the page to the index.aspx.
This works fine when I run it locally on the development machine, but when I call the login:
https://p3nwvpweb123.shr.prod.phx3.secureserver.net:8443/sitepreview/http/hebron-city.ps/wcms/login.aspx
it cuts out some of the path and redirects me to:
https://p3nwvpweb123.shr.prod.phx3.secureserver.net:8443/wcms/index.aspx
What could be the problem?
Do not Depend on the preview links in all your Redirects try using full path from the root Folder like here your root path including domain name is https://p3nwvpweb123.shr.prod.phx3.secureserver.net:8443/ so Redirect all your links like
Response.Redirect("~/wcms/index.aspx");
Response.Redirect("~/wcms/login.aspx");
This will remove the ambiguity of Wrong redirection.
and call your login page from url
https://p3nwvpweb123.shr.prod.phx3.secureserver.net:8443/wcms/login.aspx
not from
https://p3nwvpweb123.shr.prod.phx3.secureserver.net:8443/sitepreview/http/hebron-city.ps/wcms/login.aspx
I have translated a company's website to English, the aspx webpages have a masterpage.
So, the structure is like this
Server/Website's Root Folder/ ---> This directory has the webpages in their native language.
Server/Website's Root Folder/en/ ---> This directory has the webpages in the english language. Also renamed the company.master to company_en.master and changed the references to the masterpage.
Now, when I type the url www.company.com it runs fine.
Once ı try to access www.company.com/en I get a runtime error saying;
Server Error in '/' Application.
Is it possible to do this or should I get a new domain name?
In my article site some users decided to have their eMail address instead of user name
The problem starts when i'm trying to redirect to a page using RouteData and the URL ends with ".com" , for example "example#gmail.com" is a valid username so his personal page will be
http://www.mysite/user/example#gmail.com
live example
As you can see the it gets redirect to home page and relative path gets messed up, so images doesn't show
Can someone tell me why browsers don't like routedata in their url ending with .com ?
If you try ".net" or ".org" it will work, that's the issue with ".com" ?
In Windows, the .com extension is used to denote a type of executable file. Your question is tagged as asp.net - so I assume you are using IIS. IIS does not manage virtual directory names containing executable extensions such as: .vbs, .com, .exe, etc.
When a virtual directory name ends with an executable extension (such as .com, .exe, .dll, or .sh), the files in this virtual directory cannot be viewed with a Web browser. For more info, see here.
One option you have is to simply replace . with an underscore _ for personal pages. So your example above would be: http://www.mysite/user/example#gmail_com
I am attempting to redirect a gridview on selection. However, I am getting stuck on redirection when the page I am trying to redirect to is in a different folder.
The gridview is in a folder named HR. I am trying to redirect this to a file called Staff within a folder called Staff (Staff\Staff). How can I redirect to a different folder?
If e.CommandName = "Select" Then
'Add to session variable; translate the index of clicked to Primary Key
Session.Add("DetailsKey", GridView1.DataKeys(e.CommandArgument).Value.ToString)
Response.Redirect("staff\staff.aspx")
End If
Response.Redirect("~/staff/staff.aspx")
The main thing is to use / rather than \. You aren't redirecting to a folder on the server, but to a path on the website (the fact that this means a folder on your server is just an implementation detail).
You can do all the forms that you can with relative links. Hence "staff/staff.aspx" goes to the file called staff.aspx in the folder called staff that is in the current folder (assuming your folder-and-file based system). "../staff/staff.aspx" goes up a folder, then to staff then to staff.aspx. "../../staff/staff.aspx" goes up two first. "/staff/staff.aspx" goes to the root of the domain on (http://mysite.com/staff/staff.aspx, etc).
As well as all of these, "~/staff/staff.aspx" goes to the root of the application, then to staff within that, then to staff.aspx. This is useful if you work on the site such that this would be in http://localhost/currentProject/staff/staff.aspx because the project is at http://localhost/currentProject/ but deployed to http://mysite.com/staff/staff.aspx as the site is at http://mysite.com/. This way the same code works both ways.
This should do the trick
Response.Redirect("~/staff/staff.aspx");
In Classic ASP, Server.MapPath() doesn't always work properly in the Application_OnStart event within global.asa. I have an ASP page at "\testfolder\test.asp" within a virtual root, I have an XSLT file at "\xsl\transform.xsl". My virtual root is located in "c:\inetpub\wwwroot\testapp\".
I use MapPath within the ASP page to get the full path to the XSLT file. The call is:
sXslPath = Server.MapPath("xsl\transform.xsl")
Some times MapPath returns "c:\inetpub\wwwroot\testapp\xsl\transform.xsl" as expected, other times it incorrectly returns "c:\inetpub\wwwroot\testapp\testfolder\xsl\transform.xsl". The incorrect path obviously causes serious problems.
I am answering my own question here:
This problem occurs because when called in Application_OnStart, MapPath incorrectly includes the context of the page that caused the application to startup. If the first ASP page to be run when the application isn't yet started is not in the root of the virtual root then MapPath gets confused and adds the path to the called ASP page to the path it returns.
So for example if the page that started the app was in "c:\inetpub\wwwroot\testapp\folder1\folder2\test.asp" then MapPath would incorrectly add "\folder1\folder2" into the middle of the path and return "c:\inetpub\wwwroot\testapp\folder1\folder2\xsl\transform.xsl"
If your website only has files in the root folder or doesn't use MapPath in global.asa then you will never notice this little oddity. I suspect there are lots of ASP Classic sites out there that fail to startup properly sometimes because of this, but their owners just do a quick iisreset, not knowing what quite went wrong.
The result of this is that you can't reliably use MapPath in global.asa if you have a website that has ASP files anywhere other than just the root folder.
If it is a one-off website then the easiest solution is to just hard code any paths you use in global.asa.
If you sell a product to other people based on ASP Classic then hard coding the paths is not an option. You either have to move all usage of MapPath out of the application startup or deal with the issue by writing paths into your ASP files as part of the installer.
alternatively use
sXslPath = Server.MapPath("\xsl\transform.xsl")
which will then map the path from the root directory
naturally if you are developing on iis in a OS that is not a server, root will be the default website, you would have to remember to change on deployment...