ASP.NET file rebasing with a reverse proxy - asp.net

We have a site hosted on a domain that is provided by a reverse proxy from a 3rd party. The proxy provides sends the url www.example.com/nl/test/ to our server where the site is hosted on.
The site itself uses frameworks like Telerik UI for ASP.NET Ajax and the Ajax Control Toolkit.
By default when the site is loaded all the scriptresources/themes files/images are being written with the path "/scriptresource.axd" "/image.gif" the reverse proxy from the 3rd party picks this up and tries to redirect files to wwww.example.com/defaulthomepage/.
So by default ASP.NET writes paths to the domain root which is not something we want in this scenario, it should point to /nl/test/ instead.
In order to prevent default method of writing file paths the URL Rewrite extension for IIS was installed.
There are no a couple of rules in URL Rewriting which succesfully rewrite all the files to /nl/test/file.whatever but every time an Ajax request is made the following error occurs
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Is there a way to rebase the default file path of an ASP.NET site through code? We have already tried the base html tag.

Related

Initial HTTP request: index or routing?

When we send an HTTP request to a web server as to load a web page e.g. http://wwww.nothing_is_here.com, what exactly the server does as to serve our request? Till now, I thought the server was looking to find a file named index (index.html, index.php) which should have HTML content and send it back to our browser. Now, I know this is not always the case. For example, in ASP .NET where we apply routing, home/index path is added to the URL by default as for our app to be routed. That's I cannot understand is how exactly the server acts upon a similar situation. Why it does not return an error message in case there is no index file, how it knows it has to apply routing rules? How can we instruct the server what to do in either case?
What the server does when it receives a request for the root (which is what it will receive in your example), is up to the server configuration. It is not within the control of the client making the request.
The server will be configured to have a default document (file name) in such cases, which is often index.html, but equally could be any file set by the administrator of the server.
The server will often be configured to recognise different hosts (e.g. if it's serving multiple sites on the same interface:port. These different sites will often have different configuration about what the default file name(s) is/are (if any). In some cases the server is configured to display a directory listing of a server-configured site root folder.

ResponseRedirect fails when source url path contains http://

As part of an imageprocessing module I accept urls in the following format in order to process and cache externally hosted images.
http://localhost:56639/remote.axd/http://ipcache.blob.core.windows.net/source/IMG_0671.JPG?width=400&filter=comic
After processing the file, if I use Response.Redirect(url, false) to redirect the server to a valid external cache url, the server returns a 404 error response citing the StaticFileHandler as the source of the error.
If the file comes from a local source something like.
http://localhost:56639/IMG_0671.JPG?width=400&filter=comic
The server redirects to the external url without issue. Can someone explain why and provide a solution?
Note: remote.axd does nothing other than allow the local server to intercept the external url. I use the .axd extension as it isn't mapped to route by default in MVC.
I've noticed that when looking at the request path the http:// segment is replaced with http:/. I don't know whether that causes an issue.
So the reference to StaticFileHandler is the clue.
Following the actions of my HttpModule the handler is attempting to process the request. When a locally cached file is used this finds the file and all is ok. Since I am redirecting to a remote url and have a remote source the handler is finding nothing and throwing a 404 exception.
Further processing of the request has to be halted following a rewrite using the following method.
HttpApplication.CompleteRequest

How to Host Service svc on Local IIS?

I am hosting site on my local IIS, The service (*.svc) file i put in MyProjectFolder/Service directory . I am getting following error. I am calling service from ajax call direct through service path. "neo.Mysite.Net/Prent.svc"
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension
configuration. If the page is a script, add a handler. If the file
should be downloaded, add a MIME map
Most likely causes:
•The directory or file specified does not exist on the Web server.
•The URL contains a typographical error.
•A custom filter or module, such as URLScan, restricts access to the file.
Things you can try:
•Create the content on the Web server.
•Review the browser URL.
•Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here
U could refer this short and simple blog post http://weblogs.asp.net/stevewellens/calling-wcf-services-with-jquery-stripped-down

How come pages on some blogging websites lack an extension

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.

TransferRequest vs Transfer in ASP.Net

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.

Resources