How do I configure IIS 7.5 to forward all *.xml file requests to asp.net engines so i can handle them in Global.asax and rewrite the path to a *.aspx file? Now IIS is expecting to find them directly on disk. I will use this do dynamically generate my sitemap.xml
You can force static files to go through the ASP.NET pipeline by editing your web.config:
<system.webServer>
<handlers>
<add name="XMLHandler" type="System.Web.StaticFileHandler" path="*.xml" verb="GET" />
</handlers>
</system.webServer>
HTTP Handlers and HTTP Modules Overview
How to: Register HTTP Handlers
Related
I'm trying to understand how IIS knows how to start my ASP.Net Web Application My understanding so far is that, when creating a web application we create a Web.Config which defines how IIS will start it's process
So We have a Web Config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="LogRequests" type="BDBPayroll.Apps.API.Web.Shared.HttpModules.LogRequestsHttpModule, BDBPayroll.Apps.API.Web.Shared" />
<add name="MiniProfiler" type="BDBPayroll.Apps.API.Web.Shared.HttpModules.MiniProfilerHttpModule, BDBPayroll.Apps.API.Web.Shared" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
And The Global Asax:
public class WebApiApplication : WebApiHttpApplication<WebModule>
{
protected override void Configure(HttpConfiguration config)
{
config.Filters.Add(new Filters.ContextResolverFilter());
config.Filters.Add(new ValidateModelAttribute());
config.Filters.Add(new PaginationFilter());
GlobalContext<JsonFormatterRule>.Instance.SetDefaultJsonFormatter(config);
}
//...
}
Since IIS can run multiple applications e.g php, .net etc, How does IIS Know from the Web Config To run the Global Asax.
My guess is that it looks up the application type from the web config, and then searches for WebApiHttpApplication, Does anybody have any more information on this process?
Since IIS can run multiple applications e.g php, .net etc, How does IIS Know from the Web Config To run the Global Asax.
My guess is that it looks up the application type from the web config, and then searches for WebApiHttpApplication, Does anybody have any more information on this process?
As far as I know, if use send the request to the IIS.
After handling the http request by http.sys, IIS will move this request to the w3wp.exe to handle it.
Since IIS could only handle htm or html static page, IIS will use ISAPI to handle the page which IIS couldn't handle.
ISAPI is a kind of extention handler to handle different kinds of pages like php, aspx, cshtml or something else.
You could find it from IIS manager console handler mapping icon.
Image as below:
The IIS will send the request to right http hanlder according to its extension. The handler moudule(e.g asp.net isapi) will load the CLR and web application(include the globalasax) to handle the request.
I need to access a web api in an Azure Web Role from a legacy Flash Application, and in order to do this Flash needs to be able to access a file called crossdomain.xml. I have added this file to the root of the application, but if I go to https://myapp.com/crossdomain.xml in the browser the file is downloaded. How can I get the xml to be shown in the browser?
Static xml files can be served by adding the following to web.config:
<handlers>
<add name="XMLHandler" type="System.Web.StaticFileHandler" path="*.xml" verb="GET" />
</handlers>
<staticContent>
<mimeMap fileExtension=".xml" mimeType="application/xml" />
</staticContent>
I'm creating a custom server control which uploads files asynchronously to the server.
This solution uses flash element that posts the files to Generic Web handler aka ashx which then saves the posted file in a desired location.
It works grate, but with this approach I do need to create ashx file in each project, potentially, to handle the posts from the flash element.
What I would like to achieve is fully encapsulated server control that will use it's own ashx (or whatever can replace it) handler to upload the files.
Is it possible to do? Any ideas would be welcome.
Thanks.
You could include the handler within the class library containing the control and then only register it in web.config using the <httpHandlers> section:
<configuration>
<system.web>
<httpHandlers>
<add verb="*"
path="upload.ashx"
type="MyControl.MyUploadHandler.New, MyControl" />
</httpHandlers>
<system.web>
</configuration>
and if you are using IIS 7 Integrated pipeline mode to the <handlers> section:
<system.webServer>
<handlers>
<add name="UploadHandler"
verb="*"
path="upload.ashx"
type="MyControl.MyUploadHandler.New, MyControl" />
</handlers>
</system.webServer>
And if you are using ASP.NET 4.0 you could checkout the PreApplicationStartMethod infrastructure which allows you to dynamically register handlers:
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyControl.StartUp), "PreApplicationStart")]
i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's.
a task that is a bit over me since i have no experience.
ok, lets talk a bit of code:
routes.MapRoute(
"CategoryBySeName", // Route name
"products/{SeName}", // URL with parameters
new { controller = "Catalog", action = "CategoryBySeName" }
);
this works as expected, but then the client wanted ".html" at the end of paths, so i changed:
"products/{SeName}", // URL with parameters
to:
"products/{SeName}.html", // URL with parameters
which fails ( IIS 404 page - MapRequestHandler)
it seems like iis is trying to load a physical file with that name instead of passing it to the application.
Similar: ASP.NET MVC Routing to start at html page (not answered, Not duplicate)
You have to force all request through the ASP.NET pipeline, and you can do that by adding only this single line to the web.config of your application:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
You're guess that an IIS handler is probably grabbing the request prior to MVC is likely correct.
Assuming IIS 7:
http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx
You need to edit the .html handler in IIS to use ASP.NET.
You can find it in the website properties under the home directory tab in app configuration in the mappings section in II6.
Something along the lines of (version may be different):
C:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll is what you need to handle the .html files.
Changing the Application Pool from Classic to Integrated fixed the issue.
thank you guyz for your help.
Just add this section to Web.config, and all requests to the route/{*pathInfo} will be handled by the specified handler, even when there are dots in pathInfo. (taken from ServiceStack MVC Host Web.config example and this answer https://stackoverflow.com/a/12151501/801189)
<location path="route">
<system.web>
<httpHandlers>
<add path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ApiURIs-ISAPI-Integrated-4.0" path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</location>
Here's what I want to do:
I've created a class library project
and this has a class implementing
the IHttpHandler interface. Let's
call this class ZipHandler. Let's
say the namespace is Zip.
I want that whenever any Http
request comes for a zip file, my
ZipHandler should handle it,
regardless of whether the request is
to an Asp.Net application or a
normal virtual directory.
Queries:
Is it possible (it should be given
the hype about integrated pipeline
etc. in IIS 7)?
How to do it?
Here's the info I was looking for:
If you want to register your custom
HTTP handler at the IIS 7 Web server
level, you must compile your HTTP
handler into a strongly-named assembly
and deploy it to the Global Assembly
Cache (GAC) because IIS 7 only picks
up assemblies deployed to the GAC. It
does not pick up assemblies deployed
anywhere else such as the bin
directory of a particular Web site or
Web application.
We're aiming to add this handler at web server level. After deploying the handler in GAC, open the web.config available at the web server level (right click and browse -> open the web.config show here) and put something like this in the handler section (the fully qualified name of the class):
<handlers>
<add name="Ch8_RssHandler" path="*.rss" verb="*"
type="ProIIS7AspNetIntegProgCh8.RssHandler, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=369d834a77" preCondition="integratedMode" />
</handlers>
Note: The information snippets (1st para and code sample) are taken from the book:
Professional IIS 7 and ASP.Net Integrated Programming by Dr. Shahram Khosravi
Seems like a very nice book :)
This MSDN article How to: Configure an HTTP Handler Extension in IIS explains what you'll have to do. See the paragraph for the Integrated mode.
The file-name extension for .zeip must be registered in both the httpHandlers element and the handlers element.
You'll have to click Add Managed Handler in the Actions pane.
Using IIS Manager in IIS 7.0 to add a custom handler extension is equivalent to registering the handler extension in the Web.config file.
I did a test in VS2012
My handler is like this
namespace MyProject
{
public class ZipHandler: IHttpHandler
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext context) { ... }
}
}
My web.config is
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<handlers>
<add
name="ZipHandler"
path="*.zip"
verb="*"
type="MyProject.ZipHandler"
preCondition="integratedMode"
/>
</handlers>
</system.webServer>
</configuration>
In this way I can ask for "foo.zip" and have my handler get the request.
There's also a post from Rick Strahl that can help you troubleshoot things about handlers and modules: HttpModule and HttpHandler sections in IIS 7 web.config files