I have web.api 2 project. I also tried to add handler to it. But every request (http://api.xxxx.xxx/handler) which I send return error of 404 code. I realized that problem is route config, but how I can fix it?
web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
<!-- ADD THIS -->
</modules>
<handlers accessPolicy="Read, Execute, Script">
<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" />
<add name="ChatHandler" verb="*" path="/handler/" type="ProjectAPI.Handler.ChatHandler" />
</handlers>
</system.webServer>
Global.asax.cs
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}");
RouteTable.Routes.Ignore("handler/{*path}");
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
If you didn't changed the WebApiConfig routes, the default url should be:
http://api.xxxx.xxx/api/handler. I've never see a need to add this to the configuration, why's that? Change only the configuration in the WebApiConfig.Register from ~/api/ to ~/ and it should work. Post some more code, because it's like "reading from the tea leaves" :)
I've developed an ASP.NET WebApi application.
When I publish and test it to localhost IIS,I got this error at one request:
Response with status: 500 Internal Server Error for URL:
http://localhost/api/COMI/NEW/158/3
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule"
resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\POSweb.dll"
stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 5f28b9b3-0e00-439a-8fa1-e64186505b5e-->
Running it for IDE gives no error at that point.How can I fix/debug this.
route configuration:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
thanks
You need to enable stdoutlogenabled and create a log directory in your root to get the aspnet core logs to troubleshoot the actual error ... more info here https://stackoverflow.com/a/35712042/1137785
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
I've solved using TryParseExact like there
After building the web service and publishing dll files under the bin folder and web.config file under the main directory to my hosting but it shows the following error:
cs:
namespace jsonwebservice
{
public class getvideos:IHttpHandler
{
...
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear/>
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
<add value="index.php" />
</files>
</defaultDocument>
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto" />
<handlers>
<add name="getdata" path="getdata" verb="*" type="jsonwebservice.getvideos" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
I have a url route which I declare at global.asax file :
routes.MapPageRoute("RouteAdmin", "Admin/{Url}", "~/pages/MyPage.aspx", false);
But if the user tries to access mysite.com/pages/MyPage.aspx he can still see the page
Question :
Can I configure routing so that only routed paths are acceptable ?
In ASP.NET MVC views are not accessible directly by defining them using a not found handler:
<system.web>
<httpHandlers>
<remove verb="*" path="*.aspx" />
<add path="*.aspx" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="BlockViewHandler" path="*.aspx" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
Found it.
If I access directly to the aspx file so I can check this prop:
Page.RouteData.RouteHandler is null
where
if I use route url it is not null :
{System.Web.Routing.PageRouteHandler}
Edit
(better solution)
Add those 2 lines to global asax
routes.MapPageRoute("Route", "{*.}", "~/pages/default.aspx", false );
routes.RouteExistingFiles = true;
I'm getting a HTTP Error 405.0 - Method Not Allowed error while trying to make a DELETE request to a .ashx handler from the jquery file uploader I was trying to implement.
Referencing this question (http://stackoverflow.com/questions/6695587/enabling-put-on-iis-7-5-for-an-ashx-handler-using-windows-authentication) I've added the below section to my web.config file, but can't seem to get the error to go away. Are there any other tricks I'm not finding to get DELETE to work?
I'm using .Net 4.0 and IIS7.5 with the windows azure storage emulator running also.
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers accessPolicy="Read, Write, Execute, Script">
<remove name="WebDAV" />
<remove name="SimpleHandlerFactory-Integrated-4.0" />
<remove name="SimpleHandlerFactory-Integrated" />
<add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode" />
<add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="*" verbs="GET,HEAD,POST,PUT,DELETE,DEBUG" />
</authorization>
</security>
</system.webServer>
And here's the front end code calling the handler:
<td class="delete">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" data-url="/webservices/FileTransferHandler.ashx?f=df69bfd1-2a15-43e3-9310-3ca163e2aeb2" data-type="DELETE" role="button" aria-disabled="false" title="Delete">
<span class="ui-button-icon-primary ui-icon ui-icon-trash"></span>
<span class="ui-button-text">Delete</span>
</button>
</td>
I've enabled failed request tracing and it's trying to use the staticFileModule while based on the requests extension of .ashx I'd think it would try to use the SimpleHandlerFactory.
Here's the link I'm hitting: http://local.testsite.com:80/webservices/FileTransferHandler.ashx?f=df69bf1-2a15-43e3-9310-3ca163e2aeb2
Why would that link be using the staticFileModule, isn't that for images or documents like .jpg and .pdf?
Here's the final web.config section. The thing I needed to add I was missing was changing the staticFileHandler from using "all verbs" to all of them spelled out.
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers accessPolicy="Read, Write, Execute, Script">
<remove name="StaticFile" />
<remove name="SimpleHandlerFactory-ISAPI-2.0" />
<remove name="WebDAV" />
<remove name="SimpleHandlerFactory-Integrated-4.0" />
<remove name="SimpleHandlerFactory-Integrated" />
<add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode" />
<add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />
<add name="StaticFile" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
</handlers>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="*" verbs="GET,HEAD,POST,PUT,DELETE,DEBUG" />
</authorization>
</security>
<tracing>
<traceFailedRequests>
<remove path="*" />
<add path="*">
<traceAreas>
<add provider="ASP" verbosity="Verbose" />
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
<add provider="ISAPI Extension" verbosity="Verbose" />
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="405" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
If you are using PHP inside the IIS Server then follow these steps.
I have resolved the issues by adding delete verb for PHP Module.
1.Open IIS.
2.Go to configuration Editor.
3.Form Section DropDown Select System.WebServer.
4.Select Handler,It will show you the available handler click next to
count to open the handlers.
5.Goto PHP_viaFastCGI and Add Delete as verb next to POST.