I've created HttpModule in ASP.NET, and configured it successfully.
My problem is, the module is called only when I give the URL extension (i.e. aspx), if i dont put any extension, the module won't be called.
How can I solve this?
thanks
The problem is that the request is not being handled by ASP.Net - IIS 6 and below only invokes ASP.Net when it encounters a filename that it associates with ASP.Net, such as an .aspx or .axd file extension.
This is similar to the problem faced when attempting to deploy MVC applications to IIS 6 or below (IIS fails to route the requests to ASP.Net), and the solutons are also similar - you can either individually map every extension you wish to see handled to aspnet_isapi.dll the ASP.Net handler (which still won't work for URLs that don't have extensions), or you need to use a wildcard mapping to tell IIS to direct all requests to ASP.Net - note that this will include images and other static files which might get handled less efficiently than normal.
The article Deploying ASP.NET MVC to IIS 6 discusses the solutions for deploying MVC applications to IIS 6 - this discusses potential solutions with greater detail than I have space for here.
Related
I have to deal with a legacy asp.net mvc web app (.net 4). It uses some customized routing, which works fine when I use visual studio 2010's development server. However, when I use iis instead (during debugging) it does not seem to work (never used iis during debugging before).
The answer provided here does not seem to help. I already use:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Is there any other reason why the routing may not work? Thanks!
A generic post, unfortunately Internet Information System can create a slew of configuration issues. This is quite possibly it's largest pitfall. Is when you launch it on a Deployment Server, Local Server, or a Production Server the outcome may never appear to be the same.
I'll use Internet Information System Six, because it is similar to Seven and Eight but it just lacks certain features.
Inside of your project for ASP.NET MVC Web Application you'll want to right-click your project and select Properties.
You should see a tab that indicates the word: *Web**
Inside this tab towards the bottom you'll want to ensure that Use IIS Web Server is selected.
You'll want to put a Project URL in there.
This field should look like: *http://localhost/ApplicationName*. What your essentially doing here is mapping your project directory for IIS. You see each IIS Site stores a site inside the:
C:\inetpub\wwwroot
That is your Root Site Folder, where IIS will reference all of your Site Components. ** Keep in mind this Virtual Directory in projects is actually different then your IIS Configuration item listed. **
Now you'll want to open Internet Information System, you'll want to setup your File Extensions. So before doing anything in IIS, you'll want to configure your ASP.NET MVC Installer. You need to configure your mappings (ISAPI) to the .mvc extension to aspnet_isapi.dll. This step is required in order for IIS to hand off Routing Request using the .mvc extension to ASP.NET.
From a good blog post he stated:
If you’re planning to use extension-less URLs, you can skip this
section, but it may be useful to read anyways as it has some
information you’ll need to know when setting up extension-less URLs.
Mapping .mvc to ASP.NET
If you plan to use the .mvc URL extension, and are going to deploy to
IIS 6 on a machine that does not have ASP.NET MVC installed, you’ll
need to create this mapping by performing the following steps.
One nice benefit of using the .aspx extension instead of .mvc is that
you don’t have to worry about mapping the .aspx extension. It should
already be mapped assuming you have ASP.NET installed properly on the
machine.
For the rest of you, start by right clicking on the Virtual
Application node (IIS6DemoWeb in this case) and select Properties. You
should see the following dialog.
Make sure your in the Virtual Directory Tab and select Configuration. This will allow changes to the root website. This should bring up your Application Configuration Dialog. That will allow you to physically map your application. Since your using .mvc that is what you'll select.
If .mvc isn't found in the list, you can point to the Data Link Library here:
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
Now before you run the application you need to update the default routes, that way they look for the proper file extension. In your Global.asax.cs you'll want to ensure your using .mvc extension.
You would implement a method such as:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.mvc/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
}
That should allow the site to properly display. This is a very, very generic and broad example. But hopefully this points you in a good direction.
Update:
When utilizing Internet Information System Seven you have to be aware of the following:
Site Configuration
Application Pool
Database Configuration
Those three items are common culprits to incorrect configuration.
A really wonderful blog can be found here:
Another nice article can be found here:
However, this article should hit the nail directly on the head for you:
As I stated the above detail should resolve your issue. But, with the introduction of IIS 7 they have two completely different methods to allow request: Integrated and Classic.
The major difference is Integrated will perform better and includes more features. Where Classic is designed for backwards compatibility. Your route request processing method is determined by your Application Pool. With this incorrectly configured; it won't work.
Launch the Internet Information Services Manager
In the Connections window, select an application
In the Actions window, click the Basic Settings link to open the Edit Application dialog box
Take note of the Application pool selected.
By default, IIS is configured to support two application pools:
DefaultAppPool and Classic .NET AppPool. If DefaultAppPool is
selected, then your application is running in integrated request
processing mode. If Classic .NET AppPool is selected, your application
is running in classic request processing mode.
From within that box you'll be able to modify the processing mode within an "Edit Application Dialog Box".
Hopefully this additional information better assist you for your goal. The first two blogs are a avoiding IIS, where the third one focuses specifically on IIS 7. If you have any questions let me know.
I have 1 secure MVC website already hosted at say https://mysite.co.uk. This website has areas, controllers and actions as per normal:
https://mysite.co.uk/kitchen/create
https://mysite.co.uk/bathroom/edit
etc
Initially, I was told that my second MVC website would be able to be hosted under a new url: https://mysite-newsite.co.uk, so I have a new solution with.
But now unfortunately the deployment team have said it needs to be deployed under the initial main url:
https://mysite.co.uk/newsite
We are using iis7 and I have tried to achieve this using Add Application , but I just run into lots of problems with routing, nhibernate dll conflicts etc.
Can this be actually be resolved somehow in iis7 please? Or will the second MVC solution need to be re-written somehow?
Thanks
I think your best bet would be to create a sub-directory in the first application's deployed directory and put the second application there.
You can then set the sub-directory to be its own application in IIS and they will operate independently.
So, you will have url's like this:
https://mysite.co.uk/kitchen/create <-- first site
https://mysite.co.uk/[subdirectory]/controller/action <-- second site
The route urls in the second application should work, but you will need to check this.
Otherwise, you will have to merge the two applications into one solution.
I want to implement a restful service in ASP.NET. I want it to be compatible with .Net 2.0 and IIS 5+. I am constrained to not use ASP.NET MVC or REST starter kit. By reading on internet I have learned that it can be implemented using HTTPHandlers. The problem is, the request will come in as a POST request. And I want to URL to be like:
http://abc.com/MyService/MyMethod1/
and
http://abc.com/MyService/MyMethod2/
Any workarounds for this?
Thanks,
Vamyip
Your best option is to use URL Rewriting. This is non-trivial in IIS5. The methods I know of are as follows:
Method 1 - ISAPI filter
These are low-level modules that allow you to manipulate the incoming request. Programming one of these is hairy and tough to debug. If you go this route, you are better off using one that has already been built like ISAPI_Rewrite.
Method 2 - IHttpModule
These are managed ASP.Net modules that are easy to add/remove from your application. Again, you are better off using a pre-built component like UrlRewriter.NET. The issue with using one of these, (as BrainLy mentions), is that you have to configure IIS 5 to map all incoming requests to ASP.Net as follows (link):
Open Up IIS and Navigate to the “Home Directory Tab”
Select “Configuration”
Click “Add” and enter “C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked.
One interesting thing to note is that ASP.Net is itself an ISAPI module :)
Once you are able to manipulate URLs using one of these tools, you can easily rewrite the RESTful urls to be handled by your default.aspx page (or whatever handler you choose to use).
If you can allow the restriction of only IIS 7.0 and above you could use URL Rewrite http://www.iis.net/download/URLRewrite to do that pretty easily.
Can I ask why is it that you need to support IIS 5+? That is an 11 year old technology that hopefully people will move out of those platforms in favor of more recent versions. Also keep in mind support for some of those platforms is ending pretty soon.
If the concern is developers running Windows XP I would point out that IIS Express includes version 7.5+ functionality and is available for all platforms Windows XP and above.
I think this will be difficult to do because IIS 5 will not let you handle non ASP.NET file extensions without some additional configuration in IIS. That means you are limited to URLs ending in .aspx etc. To handle URLs like those in your examples you need to map ASP.NET to handle all URLs in IIS, implement some type of URL rewriting, or introduce some kind of hacky 404 redirection.
Once you have the correct mapping in place you can wire up an IHttpHandler, but you will have to parse the incoming request yourself to work out which is /MyService/MyMethod1/ and which is for /MyService/MyMethod2/. If your methods are simple then it is easy to do this with a regular expression.
You should start with a simple handler like this one.
I've done a significant amount of searching and am having difficulty finding people who have encountered a similar problem.
I have gone into the properties for my project and set it to use the local IIS web server instead of the VS Dev server. It created the virtual directory just fine. When I attempt to browse to the site, I receive the following error:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
I haven't done any custom routing rules for my project, so all of that is in its default state. The only other thing that I can think of is that there is something special that needs to be done to set up the "default" page for an MVC 2 deployment.
Any help would be greatly appreciated.
%windir%\Microsoft.NET\Framework64\v4.0.30128\aspnet_regiis.exe -ir
That solved it for me in the past. (remove the "64" if you're on 32-bit)
We are interested in adding url rewrite rules programatically from our c#\asp.net 3.5 application to our iis 7.5 web server.
Is there any API for this, or should we just write into the web.config?
Some background: we are developing a hosted CMS that will host multiple websites, each website with it's own custom url rewrites.
This means that we should also be able to handle hundred thousand url rewrite rules - if you are aware of any limitaion of the IIS url rewrite module regarding this - please say so!
important note: we can't use the RewritePath c# method because we are rewriting to different application(seperate dlls with seperate web.config files).
Thanks in advance,
Eytan.