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;
Related
I am creating a web app in asp.net, I have a Radeditor, when I clicked on Ajax spellcheck, I am getting the error of
Web.Config Registration Missing!
The SpellChecking Functionality Requires a HttpHandler registration in
web.config, please use the control smart tag to add the handler
automatically, or see the help for more information.
Telerik.Web.UI.SpellCheckHandler.axd
My web.config look like the below
HttpHandler
<httpHandlers>
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true" />
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
<add path="Telerik.Web.UI.DialogHandler.aspx" verb="*" type="Telerik.Web.UI.DialogHandler" validate="false" />
<add path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" validate="false" />
</httpHandlers>
Handler
<handlers>
<remove name="ChartImageHandler" />
<remove name="Telerik_RadUploadProgressHandler_ashx" />
<remove name="Telerik_Web_UI_WebResource_axd" />
<remove name="Telerik_Web_UI_DialogHandler_aspx" />
<remove name="Telerik_Web_UI_SpellCheckHandler_axd" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Telerik_RadUploadProgressHandler_ashx" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" preCondition="integratedMode" />
<add name="Telerik_Web_UI_DialogHandler_aspx" path="Telerik.Web.UI.DialogHandler.axd" type="Telerik.Web.UI.DialogHandler" verb="*" preCondition="integratedMode" />
<add name="Telerik_Web_UI_SpellCheckHandler_axd" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" preCondition="integratedMode" />
<add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" preCondition="integratedMode" />
</handlers>
Location
<location path="Telerik.Web.UI.WebResource.axd">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Error on page
What else should I add in web.config, as I try to work with This solution but still facing the same problem
After Implementing Rumen Jekov Solution, I am still getting the error
Regarding the Spell Check Handler Server Error, AjaxUrl property is used to set the path to the handler and is used in scenarios where you may have a UrlRewriter module which overwrites the handlers url even if they are set in the web.config. A correct value of this property is like follows: RadEditor1.SpellCheckSettings.AjaxUrl = "Telerik.Web.UI.SpellCheckHandler.aspx";
Once you set the new AjaxUrl value, go to the web.config file and update the Telerik.Web.UI.SpellCheckHandler.axd instances to Telerik.Web.UI.SpellCheckHandler.aspx
Check this article for more information about problems with handlers: https://www.telerik.com/support/kb/aspnet-ajax/editor/details/error-web-config-registration-missing!-the-telerik-dialogs-require-a-httphandler-registration-in-the-web-config-file-
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 wrote an handler that should work for all the following urls:
.../assert/a.png
.../assert/a/b.png
.../assert/a/b/c.png
but works only with the first one, here it is my code in the web.config file:
<customHandlers>
<handler trigger="~/assert/" handler="CasImagesHandler.ashx"/>
</customHandlers>
<handlers>
<add verb="*" path="*/assert/*.png" type="xxx.CasImagesHandler, xxx" name="CasImagesHandler"/>
</handlers>
<httpHandlers>
<add verb="*" path="*/assert/*.png" type="xxx.CasImagesHandler, xxx" name="CasImagesHandler"/>
</httpHandlers>
Thanks for help
i'm using web api with asp.net web forms 4.5 and i have problem in delete method .
that not work but other methods work good.
please help .
this my delete method:
[HttpDelete]
public void DeleteConversation(long id)
{
if (_repository.UserConvers(long.Parse(User.Identity.GetUserId())).All(a => a.Id != id))
return;
var item = _repository.Get(id);
if (item == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
_repository.Remove(id);
}
and this is my web config :
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthenticationModule" />
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="CKUpload" path="/Handlers/CKUpload.ashx" verb="*" type="UI.Handlers.CKUpload,UI" />
<add path="Captcha.ashx" verb="*" name="Captcha" type="UI.Handlers.Captcha,UI" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Make sure that inside your delete method in _repository class that you are calling SaveChanges(). Nothing wrong with your Method and you should be able to access it by issuing HTTP Delete to uri "/api/{controllerName}/45541"
I am trying to make the *.htm files processable by .net to route this extension, but I am unable until now. I search through tons of results on google/bing, I found something to make the mapping and to route it, but it's not working.
Note that I am using webForm, not mvc.
The mapping set in IIS is Managed Handler : path=*.htm, Handler=System.Web.UI.SimpleHandlerFactory
Here the code I am using.
Am I missing something?
Thanks!
//Web.config
<system.web>
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModue,System.Web.Routing,Version=4.0.0.0,Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
<httpHandlers>
<add verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler,System.Web, Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="*.htm" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>
//global.asax.cs
void RegisterRoutes(RouteCollection routes){
routes.Ignore("{ressources}.asd/{*pathInfo}");
routes.MapPageRoute("OnlineHelp", "Help/Content/{HelpFile}.htm", "~/Default.aspx");
routes.MapPageRoute("Default", "", "~/Default.aspx",true);
}