IIS handle static files? - iis-7

Does IIS handle request that of static file eg:
http://localhost:9000/Content/ABC.pdf
If it doesnt then can we add some setting so that the .pdf request is also handled by IIS and it passes through URLRewite module.

Asp.net only receives requests for aspx, asmx, ashx.
If a file name extension has not been mapped to ASP.NET, ASP.NET will not receive the request.
If you create a custom handler to service a particular file name extension, you must map the extension to ASP.NET in IIS and also register the handler in your application's Web.config file. For more information, see HTTP Handlers and HTTP Modules Overview.
If possible change your url to an ashx file. If not, you can map pdf to be recognized by asp.net.

Yes, IIS handles static content just fine (it does serve images up, right?).
By default it will bypass any dynamic processing and return the content directly.
If your setup does not automatically handle PDF files correctly, you may simply need to add the correct mime type to the configuration.

Related

What is the diff between http handler and ashx

I know that httphandler is different from an ashx file. But I heard it from somewhere that they are the same. I am not able to find any reading material that shows that these two are different.
Basically, ashx is to HttpHandler, what apsx is to an ASP.NET (WebForms) Page.
It's just the default extension for an HttpHandler and there's nothing stopping you from using a different extension and configuring your server to use that extension.

ASP.Net pages don't load on IIS 8

I'm doing application testing on Windows Server 2012 to check compatibility of our web apps (in .Net 4) and am having issues loading any ASPX page. I have tried uninstalling and reinstalling all of the .Net, IIS and ASP.Net roles from Server Manager numerous times. I also found that aspnet_regiis no longer works in Server 2012, it just gives a message to use the role/feature pages instead. I'm at a loss, has anyone else tried IIS 8 yet?
I get the following message:
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:
•It is possible that a handler mapping is missing. By default, the static file handler processes all content.
•The feature you are trying to use may not be installed.
•The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)
•If ASP.NET is not installed.
Things you can try:
•In system.webServer/handlers: ◦Ensure that the expected handler for the current page is mapped.
◦Pay extra attention to preconditions (for example, runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool.
◦Pay extra attention to typographical errors in the expected handler line.
•Please verify that the feature you are trying to use is installed.
• Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe.
1.To set a MIME type, use the following syntax: %SystemRoot%\windows\system32\inetsrv\appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string']
2.The variable fileExtension string is the file name extension and the variable mimeType string is the file type description.
3.For example, to add a MIME map for a file which has the extension ".xyz": appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']
Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. Determine if clients can download these file types before enabling them.
•Install ASP.NET.
•Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.
Detailed Error Information:
Module
StaticFileModule
Notification
ExecuteRequestHandler
Handler
StaticFile
Error Code
0x80070032
Requested URL
http://localhost:80/login.aspx
Physical Path
C:\Inetpub\WEBSITE\login.aspx
Logon Method
Anonymous
Logon User
Anonymous
Well, after fighting this issue for the last few days I reset the VM to the base snapshot that I took immediately after finishing the OS install. I followed the exact same steps that I documented during my first runthrough to install the IIS and App Development features then installed my apps and now it works. I have no idea why or how it worked this time where it didn't before, but at least it is working now.

ASP .NET code in SVG?

I am looking for a way that I can add .SVG files to server-side code handlers or something, so that I can have server-side code handled in my .SVG files, without needing to change to the .ASPX file extension.
I know how to do this in PHP, just not in ASP .NET.
Implement an ASP.NET HTTP handler. See HTTP Handlers and HTTP Modules Overview.
Basically, you create an implementation of the System.Web.IHttpHandler interface and register it in web.config (you can register it for any URL pattern you like, so you can serve *.svg URLs and have the handler execute your logic).
If you're running an older IIS version, you will also need to add a file extension mapping to IIS configuration. For IIS 7, all you need to do to add the mapping is to register your handler in web.config.

Processing static files via HttpModule in ASP.NET

I have statiс files in website folder, but need to check permissions for every file.
I decided to use HttpModule for that purposes.
ASP.NET receives all the http-requests (I used wildcard mapping) and
The algorith is the following:
HttpModule receives the request
HttpModule checks permissions
If access is denied then the answer is "Forbidden". If all is OK then httpModule's method just returns.
DefaultHttpHandler is automatically used to process request for static files
The problem is that DefaultHttpHandler is not effective enough (it doesn't use file cache, etc.). But IIS (without ASP.NET) works with static files in a very good way.
All I want is to let IIS serve static files after my checks.
Is there any way to implement it?
If you're using IIS7 then yes, it's quite easy. In the integrated mode, all requests go through the managed pipeline. Let IIS serve the files, but add a HttpHandler to do the checks. Or you can use one of the authorization methods that ASP.NET offers.
I have a solution that could be used to stream the file in IIS 6. It does all the good things like resumable downloads, client side caching (etag & expires) and server side caching.
http://code.google.com/p/talifun-web/wiki/StaticFileHandler
It should be easy enough to extend to include authorization before serving up the file.

Can an assembly in an ASP.NET Bin folder automatically register HTTP handlers?

Is it possible for a .NET assembly in an ASP.NET web site's Bin folder to automatically respond to certain incoming HTTP requests, as if it had an httpHandlers entry in the web site's web.config file, but without actually having to add that entry?
For example an assembly may contain the following metadata to get some embedded static resource to be available in an ordinary HTTP request:
[assembly: System.Web.UI.WebResource("SomeManifestResource", "image/gif")]
I'm looking for similar functionality that instead of returning a static resource will actually invoke an HttpHandler that is defined the assembly. Again, without actually having to add the entry to the web.config file.
No that is simply not possible.
Everything in ASP.NET that responds back with HTML output is HttpHandler somewhere in the inheritance hierarchy. So HttpHandlers are really one of the most critical part of ASP.NET runtime. Even your asp.net pages [aspx,ascx] do implement IhttpHandler to be able to serve HTML content.
You must configure them in your web.config to have them work for you.

Resources