What is an .axd file? - c#

What kind of purpose do .axd files serve?
I know that it is used in the ASP.Net AJAX Toolkit and its controls. I'd like to know more about it.
I tried Googling for it, but could not find getting basic information.

from Google
An .axd file is a HTTP Handler file. There are two types of .axd files.
ScriptResource.axd
WebResource.axd
These are files which are generated at runtime whenever you use ScriptManager in your Web app. This is being generated only once when you deploy it on the server.
Simply put the ScriptResource.AXD contains all of the clientside javascript routines for Ajax. Just because you include a scriptmanager that loads a script file it will never appear as a ScriptResource.AXD - instead it will be merely passed as the .js file you send if you reference a external script file. If you embed it in code then it may merely appear as part of the html as a tag and code but depending if you code according to how the ToolKit handles it - may or may not appear as as a ScriptResource.axd. ScriptResource.axd is only introduced with AJAX and you will never see it elsewhere
And ofcourse it is necessary

Those are not files (they don't exist on disk) - they are just names under which some HTTP handlers are registered.
Take a look at the web.config in .NET Framework's directory (e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config):
<configuration>
<system.web>
<httpHandlers>
<add path="eurl.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="True" />
<add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="True" />
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
<add verb="*" path="*_AppService.axd" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False"/>
<add path="*.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="True" />
</httpHandlers>
</system.web>
<configuration>
You can register your own handlers with a whatever.axd name in your application's web.config. While you can bind your handlers to whatever names you like, .axd has the upside of working on IIS6 out of the box by default (IIS6 passes requests for *.axd to the ASP.NET runtime by default). Using an arbitrary path for the handler, like Document.pdf (or really anything except ASP.NET-specific extensions), requires more configuration work. In IIS7 in integrated pipeline mode this is no longer a problem, as all requests are processed by the ASP.NET stack.

An AXD file is a file used by ASP.NET applications for handling embedded resource requests. It contains instructions for retrieving embedded resources, such as images, JavaScript (.JS) files, and.CSS files. AXD files are used for injecting resources into the client-side webpage and access them on the server in a standard way.

Related

asmx on an existing site gives me namespace not found

Been looking around but cannot find an answer. I wrote an asmx on VS2012 locally works good. Now deploying to the remote target site it is becoming an issue. On that site there are other asmx services and in their global web.config they have this section
...
<system.webServer>
...
<handlers>
...
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=123456789" />
...
</handlers>
...
</system.webServer>
I placed my asmx on a subfolder defining an Application on IIS8 and I'm trying to overwrite that global setting with my local web.config, tried different permutations on the local web.config with location to avoid inheritance but so far it always gives me the lovely
Server error in '/my_svc' Application
CS0246: The type or namespace name 'ForeignNS' could not be found
Is it possible to override it by only changing my local web.config? If so how? If at all possible? Target site admin will not allow to change global web.config unless it is absolutely necessary.

"Telerik" could not be found in global namespace

Currently I am working on a ASP.NET web form project which is using Telerik Ajax Version 2015.2.623.45, I have added Telerik.Web.UI.dll, Telerik.Web.Design.dll into my project reference, but it keeps giving me errors saying
The type or namespace name 'Telerik' could not be found in the global namespace (are you missing an assembly reference?)
Here's some info of my project if that may helps:
I am using .NET Framework 4, using Integrated Mode,
the dll's Aliases property is "global", and Copy Local property is True
and my web.config contains following parts:
<controls>
<add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
</controls>
...
...
<httpHandlers>
<add verb="*" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResourceSession, Telerik.Web.UI" validate="false"/>
<add verb="*" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler, Telerik.Web.UI" validate="false"/>
<add verb="*" path="Telerik.Web.UI.DialogHandler.axd" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI" validate="false"/>
<add verb="*" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.Upload.RadUploadProgressHandler, Telerik.Web.UI" validate="false"/>
</httpHandlers>
...
...
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Telerik.Web.UI.RadTextBox, Telerik.Web.UI, Version=2015.2.623.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
<add assembly="Telerik.Web.UI.RadAsyncUpload, Telerik.Web.UI, Version=2015.2.623.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
<add assembly="Telerik.Web.UI.RadAjaxManagerProxy, Telerik.Web.UI, Version=2015.2.623.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
<add assembly="Telerik.Web.UI.RadCodeBlock, Telerik.Web.UI, Version=2015.2.623.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
...
...
</assemblies>
</compilation>
...
...
<handlers>
<remove name="Telerik_Web_UI_WebResource_axd"/>
<remove name="Telerik_Web_UI_SpellCheckHandler_axd"/>
<remove name="Telerik_Web_UI_DialogHandler_aspx"/>
<remove name="Telerik_RadUploadProgressHandler_ashx"/>
<add name="Telerik.Web.UI.WebResource.axd" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResourceSession, Telerik.Web.UI" preCondition="integratedMode"/>
<add name="Telerik.Web.UI.SpellCheckHandler.axd" path="Telerik.Web.UI.SpellCheckHandler.axd" verb="*" type="Telerik.Web.UI.SpellCheckHandler, Telerik.Web.UI" preCondition="integratedMode"/>
<add name="Telerik.Web.UI.DialogHandler.axd" path="Telerik.Web.UI.DialogHandler.axd" verb="*" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI" preCondition="integratedMode"/>
<add name="Telerik.RadUploadProgressHandler.ashx" path="Telerik.RadUploadProgressHandler.ashx" verb="*" type="Telerik.Web.UI.Upload.RadUploadProgressHandler, Telerik.Web.UI" preCondition="integratedMode"/>
</handlers>
I have Googled a lot and tried all method on Telerik Forum, but it does not help...Can someone help me and tell me what am I missing, and how can I reference Telerik.*.dll correctly?
You can try removing the references and adding them again. In the properties of the references, "Copy Local" should be set to true (but I think this is the default). Also, make sure you're adding them to the correct project in your solution! (This tripped me up once.)
Finally, make sure the DLLs you are referencing are built against the same version of the .NET Framework your project is targeting. If they're not, you'll get something like the following warning when building:
Warning 1576 The primary reference "Telerik.Web.Design, Version=2014.2.724.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
Another way is to simply add the missing the references, this might give you an indication of missing dll files missing dlls. Your telerik dlls should be under C:\ Programe Files(x86)\Progress
Did you try to use the Telerik ASP.NET AJAX VS Extensions. To convert your project using the Telerik ASP.NET AJAX VS Extensions follow these steps:
Select your web site project in Visual Studio Solution Explorer.
In the Visual Studio menu select Telerik -> UI for ASP.NET AJAX -> Convert to Telerik Web Site
Use the configuration wizard to convert your web site. You can find more information about Configure wizard options in our documentation at http://docs.telerik.com/devtools/aspnet-ajax/general-information/integration-with-visual-studio/visual-studio-extensions/creation-and-configuration-wizard.
If you still prefer to manually manage the Telerik resources in you project you can take a look at http://docs.telerik.com/devtools/aspnet-ajax/general-information/adding-the-telerik-controls-to-your-project.
first of all check your target Framework of your current project
then check your assembly version of telerik control in 2 part : one in toolbox panel and the other one in project reference section,
all of them must be the same.
for detail of version assembly and Framework check out the link :
https://docs.telerik.com/devtools/aspnet-ajax/installation/included-assemblies

Can classic ASP, be process by asp .net

I coded a simple HttpModule in .net that authenticate user against a database for non .net files.
In IIS 6 I've map the .htm and .pdf extension to be executed by C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll and everything is working well.
Now I wan't to do the same thing for Classic asp pages but the .asp extension is already mapped to C:\WINDOWS\system32\inetsrv\asp.dll and mapping it to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll is not working because there is no build provider for classic ASP in .net.
Here is how my web.config file look like:
<system.web>
<authorization>
<deny users "?" />
</authorization>
<compilation>
<buildProviders>
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider" />
<add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
<add extension=".pdf" type="System.Web.Compilation.IgnoreFileBuildProvider" />
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="false"/>
<add path="*.htm" verb="*" type="System.Web.UI.PageHandlerFactory" validate="false"/>
<add path="*.pdf" verb="*" type="System.Web.StaticFileHandler" validate="false"/>
</httpHandlers>
<httpModules>
<add name="MyAuthenticationModule" type="Authentication.MyAuthenticationModule, Authentication"/>
</httpModules>
</system.web>
Is there a solution?
ASP.Net for the most part will not correctly interpret classic ASP file. If you have a very simple classic ASP page, with perhaps only a few very simple server expressions, such as a <%=Date() %> or two, you might get very lucky and find that the code still works... but I wouldn't count on it.
You can have classic ASP pages live in the same IIS web site as ASP.Net pages, but you still need to have those pages configured so that the classic ASP interpreter is responsible for them. You can also configure authentication to happen at the IIS level, or configure ASP.Net and ASP classic to share an authentication token/cookie, so that a user logs into an ASP.Net site once and the classic ASP pages are still protected by that single authentication event. However, getting this set up and working correctly is not an easy operation.

Custom server control and Generic Web handler

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")]

IIS7 file mappings - .asax, .ashx, .asap

IIS enables us to also configure Asp.Net file mappings. Thus besides aspx, IIS also invokes Asp.Net runtime, when requests have the following file extensions:
a) .ascx --> .asmx extension is used to request user controls.
Since user controls can’t be accessed directly, how and why would anyone send a request to a user control?
b) .ashx --> this extension is used for HTTP handlers.
• But why would you want to request an .ashx page directly instead of registering this handler inside configuration file and enable it to be called when files with certain ( non ashx ) extensions are requested?
• Besides, since there can be several Http handlers registered, how will Asp.Net know which handler to invoke if they all use ashx extension?
• What does the requested ashx file contain? Perhaps a definition of a Http handler class?
• I know how we register Http handlers to be invoked when non-ashx pages are requested, but how do we register Http handler for ashx page?
c) .asax --> This extension is used to request a global application file
• Why would we ever want to call Global.asax directly?
• I assume that when request is made for Global.asax, an object derived from HTtpApplication class is created, except this time no web page processing takes place?
thanx
Q - Besides Asp.Net being able to request global.asax for compilation, is there any other reason why I would choose to request file with .asax extension directly?
• ashx files don't have to be registered. They are basically a simpler aspx, for when you don't need the entire page life cycle. A common use is for retrieving dynamic images from a database.
So if I write a Http handler, I should put it in a file with .ashx extension and Asp.Net will build an HttpHandler object similarly to how it builds a page instance from .aspx file?
• If a hacker did try to make a request for one of these files, what would you want to happen? You certainly wouldn't want IIS to treat it like a text file and send the source for your app down to the browser.
Asp.Net could do the same it does with .cs, .csproj, .config, .resx, .licx, .webinfo file types. Namely, it registers these file types with IIS so that it can explicitly prevent users from accessing these files
•Just because you don't expect requests from the browser for a resource, it doesn't mean you don't want that resource handled by the asp.net engine. These extensions are also how ASP.Net picks up files to compile for the web site model sites.
But then why doesn’t Asp.Net also allow .cs, .csproj, .config, .resx, .licx, .webinfo files to be directly requested?
a) and c) - as far as I am aware, these are not exposed to process any external requests
my book claims the two are mapped in IIS
I appreciate your help
EDIT:
b) The .ashx extention is defined in a config file it's just not the web.config, its in the machine.config
<add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True" />
http://msdn.microsoft.com/en-us/library/bya7fh0a.aspx
Why use .ashx: The difference is that the .NET class that handles a .ashx reads the Page directive in the .ashx file to map the request to a class specified in that directive. This saves you from having to put an explicit path in the web.config for every handler that you have, which could result in a very long web.config.
I thought Http handler class was defined inside .ashx file, but instead file with .ashx extension only contains Page directive?
Since I’m not 100% sure if I understand this correctly: Say we have ten Http handlers we want to invoke by making a request to IIS7. I assume for each Http handler there will be specific .ashx file --> thus if request is made for FirstHandler.asxh, then handler specified inside that file will be invoked?
YET ANOTHER EDIT:
I must confess that I’m still a bit unsure about ashx extension.
I realize that by using it we can for example create 'hey.ashx' page, where Page directive will tell which class ( Http handler) to invoke when request is made for 'hey.ashx' – thus no need to register Http handler in web.config.
But if you use Http handlers that way, then they will only get invoked when requests are made for files with .ashx extension. Thus, if I want Http handler to be invoked for files with other extensions, such as .sourceC, then I will still need to register Http handler in web.config?!
A few points:
asmx files are not the same as ascx files. You use them for web services (soap) rather than web controls.
ashx files don't have to be registered. They are basically a simpler aspx, for when you don't need the entire page life cycle. A common use is for retrieving dynamic images from a database.
If a hacker did try to make a request for one of these files, what would you want to happen? You certainly wouldn't want IIS to treat it like a text file and send the source for your app down to the browser.
Just because you don't expect requests from the browser for a resource, it doesn't mean you don't want that resource handled by the asp.net engine. These extensions are also how ASP.Net picks up files to compile for the web site model sites.
a) and c) - as far as I am aware, these are not exposed to process any external requests
b) by default, it will look for a .ashx file with the path/name requested. This makes it really easy to add a handler to a web site, with no configuration necessary.
Update: In a you also mentioned asmx. My take is the book is explaining some ajax related feature, with some comments regarding:
Asp.net doesn't allow making requests pointed to .ascx.
You can make a request to a web service (.asmx) to get you the info.
There are some built in features to help you with the above.
To definitely clear any confusion you might have on what asp.net does with these requests, check the web.config in:
%systemroot%\Microsoft.NET\Framework\v2.0.50727\CONFIG
As you can see (posted mine below), asp.net excludes pretty much any of the files that you are unsure if they were receiving special treatment. Notice there is *.cs, *.acsx, *.asax.
<add path="*.asax" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.ascx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.master" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.skin" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.browser" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.sitemap" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.dll.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/>
<add path="*.exe.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/>
<add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.csproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.vb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.vbproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.webinfo" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.licx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.resx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.resources" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.mdb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.vjsproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.java" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.jsl" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.ldb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.ad" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.dd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.ldd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.sd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.cd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.adprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.lddprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.sdm" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.sdmDocument" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.exclude" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
<add path="*.refresh" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
Also, bear in mind that IIS might not be configured to map some requests (MIME types) to the ASP.NET pipeline.
a) .ascx can't be accessed directly becasue the default handler is the class System.Web.HttpForbiddenHandler
<add path="*.ascx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True" />
.asmx files can be called directly, they are webmethods (though you usually have to make POST request, unless you specify to allow GET's in the web.config
b) The .ashx extention is defined in a config file it's just not the web.config, its in the machine.config
<add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True" />
http://msdn.microsoft.com/en-us/library/bya7fh0a.aspx
Why use .ashx: The difference is that the .NET class that handles a .ashx reads the Page directive in the .ashx file to map the request to a class specified in that directive. This saves you from having to put an explicit path in the web.config for every handler that you have, which could result in a very long web.config.
--
c) Global.asax: i don't use gloabl.asax, i rather use the very elegant HttpModule solution, but it's probably setup for legacy sites that had global.asax files.

Categories