Single Page ASP application and Routing - asp-classic

I thought this would be very simple but it's proved difficult to find the information I'm looking for online... I have a single page website using ASP and I want to use query strings but I don't want to have to put Default.asp in the URL. So at the moment the URL would be something like:
http://localhost/default.asp?id=4
But I'd like something like:
http://localhost/watch?id=4
I'm not using Visual Studio so was hoping to be able to do this with a simple text editor. I'm not that familiar with ASP either so this I'm very much a newbie with these concepts.

You have 2 options.
1: Use URLRewrite extension from Microsoft that can be found here
You can set-up an inbound rule for the pattern: watch using wildcards, and add conditions that disable the rule when a file or directory actually exists. (URL Rewrite sets this by default), then create your action to point to default.asp and check the Append query string box. Then it will route all /watch url's to your default.asp page and will allow your script to read all querystrings as it does normally.
2: Use a custom 404 error page:
Point your error 404 page to the default.asp page in IIS, but you will need to use Request.ServerVariables("Querystring") to parse out the actual URL requested, since the 404 error page is not able to get your querystring by using Request.Querystring as you will be able to do in option 1. You will have to create your own url reading system, since the data returned as the querystring would be something like ?404;http://www.domain.com/watch?id=12312, instead of ?id=12312 like it would in option 1.
Personally I would use the 1st option, even though it requires to install the extension, it's more flexible and doesn't fill up the logs with 2 seperate requests like option 2 does, and its just more transparent to your script rather than creating your own url reading system as you would have to using option 2.

Related

Hide page extension when first time loaded on server.. how can i do this task?

I have a simple task but I don't know about this. When we run a page for the first time the extension will be hidden like Default.aspx run on the browser for the first time .aspx will hidden.
You can use the URL Rewrite IIS module to allow the URLs typed and seen by the user to be completely different form the URLs used by the application.

Change the broswer's address name

how can I change the broswer's address name?? For example I have this: www.example.es/Pages/site.aspx and I want this: www.example.es/site
How can I do that?? Ty.
you can use the 404 error challenge and Server.transfer() to do URL rewriting using classic asp
Things you need
How to create a custom 404 page
Regular expression pattern to recreate actual file path or a predefined list
eg:-www.example.com/pg1/ ---> /pages/pg1.asp
Simple server.transfer() to handle valid / invalid server requests.
<%
IF Request.ServerVariables("SCRIPT_NAME") = "pg1" THEN
Server.transfer("/pages/pg1.asp")
ELSE
Response.write("404 - Page not found");
END IF
%>
that's all you are doing basic level URL rewriting using classic asp.
Your question asks about .aspx (asp.net) pages, but your question is tagged asp-classic... you will get better responses to future questions by using the correct tag.
In this case: as long as you can install a module on your server, and you're server can process ASP.Net's web.config files, you can use the IIS URL Rewrite module that Graham mentioned in the comments. I've got an old ASP-Classic site that uses the module just fine.
If you can install an extension, you could also use Ionics Isapi Rewrite Filter. Some hosts have this installed already.
All things being equal, if you have the ability to run your choice, I'd go with the IIS URL Rewrite Module as I've generally seen better performance from it. But that may just be me.
If you do not have that kind of access to the server, and there's not something already installd, you may have to go with the 404 mapping Jeevaka Nuwan Fernando mentions.
There are some other options, but they depend on if you are using ASP.Net or ASP-Classic.

Serving virtual files in IIS

I have a page as part of my IIS 7 (ASP.NET) website which serves images from a database. It uses a querystring to select the image and sets the content type header appropriately (image/jpeg) so that, for example, image.aspx?ID=1234 will be displayed in the browser as a jpeg image.
What I want to do instead is offer a URI formed in a manner such as image/1234.jpg which will produce the same result. In other words, there is no actual file on the server named 1234.jpg, it's just the contents of a database record, but from the browser's perspective, it will appear as if there is such a file.
I'm sure this is possible, but I can't figure out how it's accomplished, or where to look for answers. I'm thinking it may be done with an ISAPI filter, but I haven't found an accessible path into the docs to know if that's even the correct basis for a solution.
Possibly the best option here would be to implement a URL rewrite rule that changes image/1234.jpg to image.aspx?ID=1234
You can find more on URL rewrite for IIS here.
If, for whatever reason, URL rewrite isn't an option to you, then another possible method might be to implement a custom 404 page. When your request to image/1234.jpg doesn't result in a real file, it'll end up there.
You should be able to detect the URI at that point and serve up the image.

Regexing it up with IIS re-write module

I am developing a profile-based web application where each user is assigned there own url through their username & iis rewrite mod's magic. A typical user's profile url would be http://www.mymark.com/mike
Each user is also created a blog in a multi-user wordpress installation. The wordpress url would look like this: http://www.mymark.com/blog/mike
I am trying to use the rewrite module to create more canonical urls for the user (http://www.mymark.com/mike/blog), and have tried several regex variations that I have created through RegExr(a regex generation tool) and come up with this as the pattern to match (www.|)mymark.com/([^/]+)/blog but haven't had any success so far. What am I doing wrong here?
Here is a screen shot of my re-write rule:
The entire host name (mymark.com) is not part of the URL, so you should not enter that as part of the Pattern. To make sure you easily figure it out, make sure to use Failed Request Tracing to extract the exact pattern that you should enter there:
http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/
but its probably going to be something like:
(^/])*/blog

Error When running asp.net Application in IIS

I have an application in asp.net.I configured it in IIS.When i running this application in IIS i getting an error;
Server "/" error:
Resource Cannot be Found
Error:404
Some of pages only produce this issues.Other forms are working perfectly.Without running application in IIS Its working perfectly.
If any one can answer plz send the answer immediatly.
Thank you
I assume that the urls for some of your pages are malformed.
Check in your app how you are building the paths.
Personally, i use to have a class like PathsUtil, where i build all of my paths for the pages,
so when i'm moving to IIS, it's extremely easy just to correct something (for instance add a virtual dir etc).
Update:
- for the PathsUtil i use Paths.resx where i have defined all of my paths like
Name Value
index /Site/index.aspx
add.user /Site/addUser.aspx
and so on.
And in PathsUtil i only take the value from the Paths.resx and i build the url:
string baseUrl = getBaseUrl() + (String)HttpContext.GetGlobalResourceObject("Paths", "index");
I've just moved to an IIS7 server, and there i've created a virtual dir "gramma"
You can note that was a piece of cake only to add "/gramma" in Paths.resx, in front of each url :)
Look for the Response.Redirect() calls in the page previous to the form you are getting the error. Just make sure that any harcoded URL for the form supplied to the Response.Redirect() call is correct.
EDIT..
Also, look for If you are navigating to a form which is in a different directory than the current one. For example:-
Response.Redirect("../SomeForm.aspx");
will redirect to an ASPX page just one level up of the current one. Each pair of dots implies one directory level up.
In thses cases, I think, you are better off using ~ (tilde) character which will always take the path from the root. So the mistakes happening because of incorrect number of dots can be minimised.Try something like this:-
Response.Redirect( this.ResolveUrl("~/Myfolder/SomeForm.aspx") );
More details for the ~ and ResolveUrl here.
This can also happen If you have window.location calls in javascript if you assign an incorrect URL to the same.

Resources