Rename and/or Change Path to scriptresource.axd - asp.net

We have a requirement that the root of our site is actually at domain.com/xyz/ and we can't have /xyz/ be a virtual directory. Some modules in our site are leveraging the ScriptManager which is by default trying to reference domain.com/scriptresource.axd?blah=blah. The scriptresource.axd will not be resolved in this case. We have made it so the references to scriptresource.axd are now change before getting sent to the client to be /xyz/scriptresource.axd but this isn't working.
My suspicion is the ScriptResource Handler Mapping is not picking up the call because of the xyz. I have tried to update the Handler mapping using IIS Manager or by editing the \inetsrv\config\applicationhost.config, \frameworkv4.blah\web.config and \framework64\v4blah\web.config but these seem to not work either.
Can someone tell me how I could get the ScriptResource handler to handle something other than /scriptresource.axd.

You can try with urlMappings with something like:
<system.web>
<urlMappings enabled="true">
<add url="~/xyz/default.aspx"
mappedUrl="~/scriptresource.axd"/>
</urlMappings>
...

Related

404 Not Found aspx file but it is there

I´m using Plesk and in Web scripting and statistics I have Microsoft ASP support in ON.
I uploaded a application (which works correctly in my PC) to a directory and it can be shown but when I go to the aspx file it shows me the 404 error (The path is the correct).
I noticed that some files in "shtml" extension are neither shown by the server.
This is my very first time with ASP.NET, ISS8 and Plesk. I don´t know what to do. I will thank you for your help
You have to set the HTTP Handler Extension. If you have no access to IIS directly, you could do on the web.config:
Open the Web.config file for the application, locate the httpHandlers element of the system.web section and add an entry for the file-name extension
Example:
<system.webServer>
<handlers>
<add name="SampleHandler" verb="*"
path="SampleHandler.new"
type="SampleHandler, SampleHandlerAssembly"
resourceType="Unspecified" />
</handlers>
</system.webServer>
For more configuration options please refer to:
https://msdn.microsoft.com/en-us/library/bb515343.aspx
and
https://msdn.microsoft.com/en-us/library/46c5ddfy(v=vs.100).aspx
Check also the Custom Handler Policy of Plesk that should not be enabled:
https://docs.plesk.com/en-US/onyx/administrator-guide/plesk-administration/securing-plesk/custom-handlers-policy.76787/
Here I've found also another interesting document:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/handlers/
Scroll down and you'll find a piece of code to add the handlers programmatically, even if I suggest you to add them in your web.config

Executing a managed module for a rewritten URL in IIS7 Integrated Mode

In my ASP.NET app, I have two HTTP modules. One of them is used for rewriting URLs, the other is used for app-specific stuff (custom authentication .. etc). The URL-Rewriting module is executed for all requests, while the other module is only executed for managed file extensions, like .aspx
Here's how the modules are defined in web.config (note that preCondition is blank for UrlRewriteModule. This cause it to get executed for all requests):
<system.webServer>
<modules>
<add name="UrlRewriteModule" type="MySite.UrlRewriteModule" preCondition="" />
<add name="SiteModule" type="MySite.SiteModule" preCondition="managedHandler" />
</modules>
</system.webServer>
In UrlRewriteModule I use RewritePath() to rewrite some URLs (directory-like) into files with query strings. For example, from "/p/5/some-thoughts-about-the-future/" to "/post.aspx?id=5"
Now, I was under the impression that when a URL gets rewritten, IIS7 executes the managed module (SiteModule in this case) if the new URL is for a managed extension (like .aspx). But, this doesn't seem to be the case. I noticed that SiteModule doesn't get executed for any rewritten URLs.
Am I missing something (or doing something wrong) or is this the normal behavior in IIS7?
I came across Server.TransferRequest() which actually solves the problem (behind the scence, it involves creating a new child request). But, this can also cause a lot of overhead esp. under server load, and I generally prefer to avoid it.
So, is there a way to get SiteModule to execute whenever a URL gets rewritten without using Server.TransferRequest()?
Thanks!

Puzzling wildcard problem in IIS7 & Module

We have an ASP.NET 3.5 app running in IIS6 we're migrating to IIS7 & the integrated pipeline. Our app does some very simple URL rewriting to examine a URL like this:
website.com/dealer/page.aspx
stripping 'dealer' out, looking it up in the DB for context and going to page.aspx.
In IIS6 this was a wildcard map. I moved the module to the right place in web.config for IIS7:
<system.webServer>
<modules>
<add name="ModuleRewriter"
type="Insignia.Catalog2.ModuleRewriter, Insignia.Catalog2"
preCondition="" />
And it works - almost. Paths like these work:
website.com/dealer/page.aspx
website.com/dealer/
The latter defaults to the index.aspx page. My problem is, this one doesn't:
website.com/dealer
note the missing slash at the end. I get a 404. What am I missing?
UPDATE:
It has something to do with the Static file handler - if I disable that, the URL maps correctly, but then static stuff doesn't work...
Well, I got it to work by modifying the modules tag:
<modules runAllManagedModulesForAllRequests="True">
but this is definately cargo-cult-ish because i don't know what it's doing yet.

Extensionless Page Requests

I have a customer of ours that sent out a publication referring to my site but they used the wrong address...they did not provide a page name...it looks like this:
mywebsite.org/Resources/toolkits/bridging
when it should have been
mywebsite.org/Resources/toolkits/bridging/default.aspx
Is there a way to tell ASP.NET to default to this default.aspx when it sees this kind of request or even better, have IIS 7 handle this easily?
This site is live so I would like to avoid having to introduce code if possible.
As per other suggestions, this should be done in the IIS configuration for your website using the IIS Admin tool.
There is however, another alternative - you can add a section in the web.config of your actual ASP.NET application, allowing you to override the IIS configuration right from your application:
<system.webServer>
<defaultDocument>
<files>
<clear />
<!-- Specify each of your files by order of preference here -->
<add value="Default.aspx" />
<add value="Index.aspx" />
<add value="MyOtherPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
The caveat to this though is it may be a little obtuse when the IIS administrator can't figure out why the server configuration isn't working the way he's got it configured. It's not always right to do something just because you can.
Finally, just in case you don't have access to the IIS server or your IIS administrator has reasons for not adding Default.aspx to the default document list in the IIS configuration and for whatever reason, you don't wish to override the IIS configuration in your web.config file, then the quickest and simplest way is to simply create a file called default.asp in that directory containing:
<% Response.Redirect("default.aspx") %>
Default.asp is in the default document list on IIS. The code will automatically redirect the call to the correct page. The downside to this approach though is that there's a performance hit - every time someone calls default.asp - directly or otherwise, the redirect needs to happen which isn't free.
In the Documents tab of the web site properties in IIS you can specify default documents. If you are using .Net2.0 or later on that machine then Default.aspx should already be set....
Default.aspx is not, oddly enough, set as the default document in an IIS installation; In IIS 7, the setting is under "HTTP Features", called "Default Document". Add default.aspx to that list and you should be OK.
If not, you'll need to add a 404 handler that redirects when it sees that URL.

IIS Wildcard Mapping not working for ASP.NET

I've set up wildcard mapping on IIS 6, by adding "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll", and ensured "Verify that file exists" is not checked :
on the "websites" directory in IIS
on the website
However, after a iisreset, when I go to http://myserver/something.gif, I still get IIS 404 error, not asp.net one.
Is there something I missed ?
Precisions:
this is not for using ASP.NET MVC
i'd rather not use iis 404 custom error pages, as I have a httpmodule for logging errors (this is a low traffic internal site, so wildcard mapping performance penalty is not a problem ;))
You need to add an HTTP Handler in your web config for gif files:
<system.web>
<httpHandlers>
<add path="*.gif" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="true"/>
</httpHandlers>
</system.web>
That forces .Net to handle the file, then you'll get the .Net error.
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /test.gif
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
You can try use custom errors to do this.
Go into Custom Errors in you Website properties and set the 404 to point to a URL in your site. Like /404.aspx is that exists.
With aspnet_isapi, you want to use a HttpModule to handle your wildcards.
like http://urlrewriter.net/
You can't use wilcard mapping without using ASP.net Routing or URLrewriting or some url mapping mechanism.
If you want to do 404, you have to configure it in web.config -> Custom errors.
Then you can redirect to other pages if you want.
New in 3.5 SP1, you set the RedirectMode to "responseRewrite" to avoid a redirect to a custom error page and leave the URL in the browser untouched.
Other way to do it, will be catching the error in global.aspx, and redirecting. Please comment on the answer if you need further instructions.

Resources