I have a web application running in .net framework 2.0 and hosted on IIS 7.5. The app pool is running in classic mode. I want to intercept all the requests containing .txt files. Below is my entry in web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="NES.HiLo.Security.CommunityResource, NES.HiLo.Security" verb="*" path="*.txt" type="NES.HiLo.Security.CommunityResource, NES.HiLo.Security" />
</handlers>
</system.webServer>
<httpHandlers>
<add verb="*" path="*.txt" type="NES.HiLo.Security.CommunityResource, NES.HiLo.Security" />
</httpHandlers>
When I m making requests for URL like
http://local.mysite.com/media/CLT/ResourceUploads/1000277/Test1.txt
the handler never kicks in, the control never comes inside the code in the handler.
Any ideas what I m missing? thanks
According to the MSDN example of registering handler in IIS 7.0 in classic mode, you are missing a couple of attributes:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="CommunityResourceHandler" verb="*" path="*.txt"
type="NES.HiLo.Security.CommunityResource, NES.HiLo.Security"
modules="IsapiModule"
scriptProcessor="FrameworkPath\aspnet_isapi.dll"
resourceType="File" />
</handlers>
</system.webServer>
<httpHandlers>
<add verb="*" path="*.txt" type="NES.HiLo.Security.CommunityResource, NES.HiLo.Security" />
</httpHandlers>
Related
For opening and saving Office files I integrated ITHit WebDav server to my solution. WebDav is implemented in a separate project but in the same solution. Local it works fine, I can open and save Word and Excel documents. But after deploying, when I try to open File, following error comes up:
Sorry, we couldn’t open the File “http://MyWebSite.de/Storage/test.xlsx”
Microsoft Excel cannot access the file “http://MyWebSite.de/Storage/test.xlsx”.
There are several possible reasons:
- The file name or path does not exist.
- The file being used by another program.
- The workbook you are trying to save has the same name as a currently open workbook.
File is on a right place and the application have full rights on it.
Local WebDav project have his own web.config. But after deploy there are only web.config from WebSite project and WebDav is a .dll file in Bin folder.
WebSite web.config severside and local:
...
<location path="Storage">
<system.web>
<httpHandlers>
<clear />
<add verb="*" path="*" type="WebDav.DavHandler, WebDav" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="My WebDAV Handler" path="*" verb="*" type="WebDav.DavHandler, WebDav" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
...
WebDav web.config local:
...
<system.web>
<httpHandlers>
<clear/>
<add verb="*" path="*" type="WebDav.DavHandler, WebDav"/>
</httpHandlers>
<httpModules>
<remove name="FileAuthorization"/>
<add name="ITHitPutUploadProgressAndResumeModule" type="ITHit.WebDAV.Server.ResumableUpload.PutUploadProgressAndResumeModule, ITHit.WebDAV.Server"/>
<add name="ITHitPostUploadProgressModule" type="ITHit.WebDAV.Server.PostUploadProgressModule, ITHit.WebDAV.Server"/>
</httpModules>
<httpRuntime executionTimeout="2400" maxRequestLength="2097151" requestPathInvalidCharacters="" relaxedUrlToFileSystemMapping="true" targetFramework="4.5"/>
<customErrors mode="Off"/>
<authentication mode="None"/>
<authorization>
<allow users="*"/>
</authorization>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<compilation targetFramework="4.5" debug="true"/>
</system.web>
<system.webServer>
<handlers>
<clear/>
<add name="aspnet_isapi 32-bit ASP.NET 2.0" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32"/>
<add name="aspnet_isapi 64-bit ASP.NET 2.0" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64"/>
<add name="aspnet_isapi 32-bit ASP.NET 4.0" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32"/>
<add name="aspnet_isapi 64-bit ASP.NET 4.0" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64"/>
<add name="My WebDAV Handler" path="*" verb="*" type="WebDav.DavHandler, WebDav" preCondition="integratedMode"/>
</handlers>
<modules>
<remove name="FileAuthorization"/>
<add name="ITHitPutUploadProgressAndResumeModule" type="ITHit.WebDAV.Server.ResumableUpload.PutUploadProgressAndResumeModule, ITHit.WebDAV.Server"/>
<add name="ITHitPostUploadProgressModule" type="ITHit.WebDAV.Server.PostUploadProgressModule, ITHit.WebDAV.Server"/>
<remove name="WebDAVModule"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
<security>
<requestFiltering allowDoubleEscaping="true">
<fileExtensions>
<clear/>
</fileExtensions>
<hiddenSegments>
<clear/>
</hiddenSegments>
<requestLimits maxAllowedContentLength="2147483648"/>
</requestFiltering>
</security>
<staticContent>
<mimeMap fileExtension=".pkg" mimeType="application/octet-stream"/>
<mimeMap fileExtension=".deb" mimeType="application/octet-stream"/>
</staticContent>
</system.webServer>
...
How could i solve this Problem?
I am implementing a RESTful web services host using ASP.Net 4.5 and Web Api 2 Attribute Routing. I also included Web Api Help Pages. When I run it locally through Visual Studio 2012 on IIS Express it works great and looks really cool; it displays the default /home/index page with an API menu that shows the documentation for all my RESTful API functions. I have also tested all the API methods with SOAPUI and running locally everything works perfectly.
But the URL routing absolutely refuses to work when deployed to IIS 7.5 on Windows 2008 Server R2.
When I browse the site I get:
403 - Forbidden: Access is denied.
If I try the /home/index or any of the routes of my web api methods I get:
404 - File or directory not found.
I have installed .Net 4.5 on the server and then went to Windows\Microsoft.NET\Framework64 and ran:
Aspnet_regiis -i
iisreset
I deployed my app to IIS and set the Application Pool to use .Net Framework v4.0.30319 and Managed pipeline mode: Integrated.
I have the following settings in my web.config:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="None" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
I have tried many different variations on the web.config entries. For example, the suggestion in this post does not work either:
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
<!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
</modules>
Nor does changing the Handlers section like this have any effect:
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<remove name="WebDAV" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
I did try turning directory browsing on and then it showed the website contents just fine, so the 403 Forbidden error is because directory browsing was forbidden.
But I don't want to browse the contents, I want URL routing to work. In RouteConfig.cs file I have a default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
So if URL routing were working then it should show the Home/Index view by default.
I also tried adding an Index.html file to the site and that worked fine too. So the website works fine as a website, but URL routing refuses to work.
Try to add this attribute to < modules > tag in web.config
runAllManagedModulesForAllRequests="true"
I have a web application which talks to a local service (also mine) and produces results from the RESTful calls.
I have deployed the web application through IIS 7 on my system.
So far it looks fine, except that I am not able to perform POST operations, they just seem like NOP's.
Although, when I install VS 2012 on the machine the POST operations start working. I am not sure what exact thing the VS 2012 install sets which causes the POST operations to work.
Any hints?
You have to enable POST operations in your web.config file. A simple implementation is demonstrated below
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Make sure to inlcude this in your config file:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
I am facing an error on the tree view control. Image is shown below.
What could be the potential reasons for it. I have transferred published code from one PC to another. The target machine is having windows 2008 server.
Everything is fine except the treeview control:
What could be the potential reasons for it?
Update
Here is an excerpt from my web.config
<system.webServer>
<validation ntegratedModeConfiguration="false" />
<handlers>
<add name="ReportViewerWebControl"
path="Reserved.ReportViewerWebControl.axd" verb=""
type="Microsoft.Reporting.WebForms.HttpHandler"
resourceType="Unspecified"
requireAccess="Script"
preCondition="integratedMode" />
<add name="ReportViewerWebControlHandler"
preCondition="integratedMode"
verb=""
path="Reserved.ReportViewerWebControl.axd"
type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
This happens when you transfer files from one server to another but miss out the mapping for axd files.
Many controls embed images inside dlls and retrive them using WebResource.axd.
A common cause is moving from one version of IIS to another.
In IIS6 you would map it as:
<httpHandlers>
<add verb=”Get” path=”WebResource.axd”
type=”System.Web.Handlers.AssemblyResourceLoader” />
</httpHandlers>
However in IIS7 you will need
<system.webServer>
<modules>
</modules>
<handlers>
<add name=”webresources” verb=”Get” path=”WebResource.axd”
type=”System.
Web.Handlers.AssemblyResourceLoader” />
</handlers>
</system.webServer>
I am developing an ASP.NET MVC applications with MS Visual Studio 2008 SP1.
My project structure is the default one:
Project |-Content |-css |-img |-Models |-Views
|-Controllers
The thing is, I am able to access all the content placed under Content directory provided the file is included in the project. On the other hand, if I happen to have an image (I.E. an image uploaded by the user) that's on the right physical directory (Project\Content\img) but is not included in the project, I keep getting a 404 error when I access them with a browser.
I think my URL is correct:
http://localhost:1260/Content/img/my_image.jpg
And I do have a file under Project\Content\img\my_image.jpg.
What can be wrong? Am I forced to include all the files on the project? I don't think so, because that would mean that I can't have images uploaded and saved by the web users this way.
Thanks a lot.
If you're hosting your project with IIS 7, you must add he content-type in IIS 7(Handler Mapping). But if you're hosting your project with the Asp.net Developer Server, it's not required.
Using the following code in web.config file
<configuration>
<system.webServer>
<handlers>
<add name="css mapping" path="*.css" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
<add name="js mapping" path="*.js" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
<add name="gif mapping" path="*.gif" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
<add name="jpg mapping" path="*.jpg" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
<add name="png mapping" path="*.png" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>