I have been making my blog and wanted to know how come some blogs have web-address like 'www.xyz./articles/15748', while my blog have addresses such as 'www.xyz/articles/test.aspx'. I mean whether they are using some form of xml to populate their predefined webpage. If not so why is their web-page is not having any extension such as '.php' or '.htm' or '.aspx'.
It can be done with Url Rewriting.
For example how to use it in Asp.Net - http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Basically it's a module that rewrites incoming url to that one that WebServer can process, and then rewrites output urls to the same as input urls
It depends on the framework they are using, if they are re-writing their URL's with a module in their web server, or handling HTTP requests with a custom HTTP handler (ASP.Net).
When calling a url that is suffixed with aspx, that means you are requesting a physical page that exists on a server, which is then trotted through the ASP.Net runtime using the WebForms framework and delivered to your browser.
Now, if you use the MVC framework instead of the WebForms framework, then your URLs don't refer to a page, but to objects and functions. If I were to request /User/Edit/1, that URL could map to the Edit function on User object, and we would pass in 1 as an argument.
In addition, some web servers have URL Rewriting functionality that allows you to map one URL to another, so it could listen for URL's without a suffix, and transparently route the request to a physical page.
Finally, in ASP.Net at least, you can write handlers in your application that will listen for HTTP requests, and if it so chooses it could also perform some transparent routing.
These are just a few ways, there are certainly others.
Related
I am working on a fairly simple API where a 3rd party makes a post to my server and I reply with data. However, I am hitting a brick wall with one of their requirements:
"All the URLs in the API below do not use a trailing slash and you cannot redirect to a URL that contains one."
Combined with:
"Requests are sent by adding "/api_name" to your endpoint and sending the params explained below in a POST request."
If I don't have a trailing slash, I receive a "HTTP Error 405 - The HTTP verb used to access this page is not allowed. Internet Information Services (IIS)" error since you cannot post to a directory.
I have been searching all day for a resolution and have come up with nothing. I cannot be the only one with this issue.
This is on a windows 2003 server so I would prefer to stick with either asp classic or .net.
Here is a link to a site that details how to add a handler mapping:
add fast CGI handler to IIS
You can follow those steps to set .NET as the handler to any extension. So, if it is possible to set your "api_name" to something like "myservice.api" and then you add ".api" as an extension for the .NET ISAPI handler, then you should be able to route their calls to your service. If you cannot change your "api_name" in their system to something with a period in it (which, really you could set "api_name" to "myservice.asmx" if you wanted to) then you will have to try to wrangle with extensionless URL's in IIS 6. This takes a little more work from what I recall:
.NET extensionless URLs as they are needed for .NET MVC 3 on IIS 6
I have gone through the links mentioned below,
iis forum and HttpModules & Server.Transfer / Server.TransferRequest / RewritePath problems. but unable to catch the concept behind these transfer methods.
How are they works? And which one is preferred in different situation?
Can someone explain me TransferRequest vs Transfer methods for server side transfer in asp.net and its roles?
Thanks in advance
HttpServerUtility.Transfer Terminates execution of the current page and starts execution of provided URL.
This basically maps and executes a new ASP.NET Page (or serves a static file) corresponding to the url provided. It does this in-place in the current request pipeline, without applying new configuration to the new url, or re-running IIS modules for the new url. Because of this, its very fast, but it also prevents a lot of scenarios that are possible with TRQ.
HttpServerUtility.TransferRequest Performs an asynchronous execution of the provided URL.
This is a full IIS child request under the covers, which allows it to re-run the entire request pipeline for the new request as if it was a separate request, getting the correct configuration for it, and running all of the normal IIS modules including authentication, authorization, etc. For example, IIS will apply the authorization rules for the new url, as opposed to the previous url.
TransferRequest re-runs the entire request pipeline as if it were a separate request. This means that IIS and ASP.NET modules are re-applied; authentication and authorization rules for the new URL will be honored. Note that TransferRequest requires the integrated pipeline mode of IIS 7+, and the transfer can be to an ASP page or another resource like an XML file.
Transfer transfers execution from one ASP page to another ASP page on the server. Unlike TransferRequest, IIS and ASP.NET will NOT verify that the current user is authorized to view the resource delivered by the Transfer method. If you need to force reauthorization, and integrated pipeline mode is not an option, call Redirect instead of the Transfer method. Redirect triggers a client-side redirect so that the new request will be subjected to all authentication and authorization logic of IIS and ASP.NET.
We have a number of existing clients that point to urls like:
http://sub1.site.com/images/image1.jpg
/images is a virutal directory that points to a directory that actually contains image1.jpg on that server.
We're moving all of the files out of this directory and onto a separate server that will not run this same application.
The file will now only be available at:
http://sub2.site.com/image1.jpg
What is the best way to make it so clients requesting
http://sub1.site.com/images/image1.jpg will get the content that now resides at http://sub2.site.com/image1.jpg?
A few requirements:
We need the actual content to be returned through that url - not a 302 response.
We cannot modify the IIS server configuration - only the web.config for the site
Again, we're running asp.net 3.5
Thanks.
Not totally sure this would work, but you could setup URL Routing on the old site so all requests are sent to a handler and within that handler you could do a web request to get the file from it's new location.
I use a variation of the process to map image URLs to different locations and my handler does some database queries to get the mapped relationship and provide the correct image. I don't see why you could do a web request to get the image.
Since you are using IIS7, you can use the built in URL rewrite module.
You would want an inbound and an outbound rule to change \images\image1.jpg to \image1.jpg
It can get pretty involved, but this should be rather simple.
Assuming you can add handlers to your site (as in add a DLL to your /bin directory in the site) and with the restriction that you can't send 302 responses for better performance, then alternatively you could write a custom handler to grab all requests that match that URL pattern, do the web request for the sub2.site image from the original site via web client code, then serve it back out of the original site, sub1.site.com.
See How To Create an ASP.NET HTTP Handler by Using Visual C# .NET for the very basics of creating and setting up a custom handler. Then use the HttpWebRequest to make the request of sub2.site.com, as in the guide A Deeper Look at Performing HTTP Requests in an ASP.NET Page. Plus a little other code to handle errors, timeouts, passing the image through with as little processing and memory usage as possible, etc.
Depending on the response time/lag between the two servers, this may be slow, but it would fit all your requirements. But if the point of moving the images to site 2 was for performance (CPU or memory) or bandwidth limitations, then this solution would nullify any gains — and would actually make things worse. But if they were moved for other business or technical reasons though, then this solution might be helpful still.
If you have other control over the server or anything upstream from the server, you could use mod_proxy (or similar Windows/IIS tool) to intercept those URLs and forward them to another server and respond back with the real request. Depending on your network configuration and available servers, this could be the simplest, best performing solution.
Can IIS be configure to forward request to another web server? on serverfault has a quick process and link for an IIS 7.5 solution.
Here is a picture I captured from < Professional IIS >
I am wondering why the web request and the resulting web content as the response have to go through the same ISAPI filters or applications in a circle fashion. I know that ISAPI applications and Filters are nothing but Win32 DLLs. This circle fashion is kind of like a function call/return manner, i.e., when the web request comes, the exported functions of ISAPI Filters are invoked, and then the Filters invoke the WWW Service, and the WWW Service invoke the exported functions of ISAPI Applicaitons, and they return all the way back reversly. So is this the root cause? (I hope you understand what I mean.)
Many thanks.
Typically, in IIS, WWW service would server web content - it would map the resource to appropriate ISAPI Extension (or handler) - mapping is typically done on the basis of request resource extension. Its extension's responsibility to throw actual content (say html) that will be then returned back to browser via www service. ISAPI filters sits in between - they can modify the request before ISAPI extension/application can process it. Similarly, they can modify the response (content) generated by the application before it is returned to the browser.
I believe that following would be better resources to understand IIS Architecture
http://learn.iis.net/page.aspx/101/introduction-to-iis-7-architecture/
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/843df643-1dbb-4fb6-910d-ec1965fa9e43.mspx?mfr=true
Imagine a Web Forms application with routing.
A clean page name like:
http://www.mywebsite.com/home
Might have an underlying of URL of:
http://www.mywebsite.com/page.aspx?id=3
If a user enters http://www.mywebsiter.com/page.aspx?id=3 into a browser, I need to redirect to http://www.mywebsite.com/home
Is this possible to do?
I can't work out a way to do this as the routing engine is not executed for a physical page and in the page.aspx Page_Load method I have no way of knowing whether the URL was entered directly or was the result of a route.
You can use the Page.RouteData.Values collection to detect if the page is being loaded due to routing, rather than a direct URL. That can be done in Page_Load().
If there are route data values (you would likely check for values that you would know should exist), then they are fine. If there are no route data values, the page has loaded 'directly', and you should redirect them.
Check out the IIS URL rewrite module.
You could also look at things like disabling routing for files (RouteTable.Routes.RouteExistingFiles = false;) - that could be dangerous though!