asp.net - URL rewrite IIS for static.example.com -


I am developing in asp.net and I am applying many applications with this folder structure:

< Pre> WWW - & gt; IMG - & gt; CSS - & gt; JS - & gt; ASPX

For example:

  www1.example.com/IMG/file.png  

My goal All the incoming requests in the subdomain for IMG, CSS and JS are to be rewritten. It is such that:

  www1.example.com/IMG/file.png  

or

  www2.example . Com / IMG / file.png  

will be for:

  static.example.com/IMG/file.png  

They should use their own folders in their own sites, it should be routed only through static.example.com. I know that I can do this with Apache, but there is no experience with IIS yet.

How is this technically possible? I have total rights on my IIS 7.5 I have many applications with the same structure and I want to use every IMG, CSS and JS folder. Do I have a performance increase?

Edit: 28.10.2014

Hopefully this will be a bit obvious with this image. Thanks for your reply, it helped me a lot! That's why I can rewrite the "url" on "static.server.com" and now I want the image from the right source which is either www1.server.com/img/abc.png or www2.server.com/ Img / abc can be. Png The static website should not have any real path, it should be just an empty website that listens on the host header or distributes posts / images, CSS and JavaScript with the correct source. Enter image details here

Thanks in advance,

Daniel < /p>

You can use httpmodule as described in this . So you can use the code from a single question and modify it according to your requirement.

  Private Zero application_BeginRequest (Object Source, EventArgs E) {// HttpApplication and HttpContext Object Build Object // Request Access and Response Properties HTTP Application Application = (HTTPPC) source; HttpContext Reference = Application. Concept; String filePath = context.Request.FilePath; String full path = context request. URLAssualsUURI; String File Extension = Virtual Path Utility.gate Extension (File Path); If (fileExtension.Equals (".gif")) {context.Response.ContentType = "image / gif"; Context.Response.Redirect (fullPath.Replace ("www.example.com", "static.example.com")); }}  

Update

Your web.config file may contain something like this

& lt; Rewrite & gt; & Lt; Rules & gt; & Lt; Rule name = "Forward to static file server" & gt; & Lt; Mail url = "^. + \. (? Jpg | bmp | gif) $" / & gt; & Lt; Action type = "rewrite" url = "http: // static_file_server / {R: 0}" /> & Lt; / Rules & gt; & Lt; / Rules & gt; & Lt; / Rewrite & gt;

More info


Comments