locked
urlrewriting doesn't work with httpmodule RRS feed

  • Question

  • User1473066820 posted

    hi all

    i ve the following module for url rewriting:

    public class UrlRewriter : IHttpModule{

    private HttpApplication app;

    public UrlRewriter()

    {}

    public void Init(HttpApplication context)

    {

    context.BeginRequest += new EventHandler(BeginRequest);

    app = context;

    }

    void BeginRequest(object sender, EventArgs e)

    {

    Match m = Regex.Match(app.Context.Request.Path,"subsites/.+",RegexOptions.IgnoreCase);

     

    if (m.Success)

    {

    app.Context.RewritePath("~/default.aspx?id=" + m.Value.Replace("subsites/", ""));

    } }}

     and when i try this url:

    http://localhost/UrlRewriter/subsites/ahmed.aspx

    it works fine but when i remove the .aspx at the end it doesn't, can anybody help fixing this ?

    thx

    Sunday, July 15, 2007 8:30 AM

Answers

  • User-225114762 posted

    Goto IIS MMC applet. Right-click your application virtual directory. Select properties. On the tab 'Virtual Directory', click 'Configuration...'. On the tab 'Mappings" click the Add-button. Browse to the ASP.NET isapi extension, typically c:\Windows\...\v2.0.50727\aspnet_isapi.dll, enter .* as the extension. Uncheck the 'Check that file exists' checkbox. Please note that you may need to move focus back and forth a bit in the dialog to get the 'OK' button to become active due to a bug in the dialog.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2007 8:15 AM

All replies

  • User1001868398 posted

    Try this below? 

    if (app.Request.Url.AbsolutePath.ToUpper().IndexOf("SUBSITES/.+",") > -1 )

    mSuccess = true;

     

    You can use one the works and modify it to your needs:

    http://alpascual.com/blog/al/archive/2006/06/19/Http-Module-Skeleton-.aspx

     

    Sunday, July 15, 2007 9:48 AM
  • User-225114762 posted

    It's probably because you have not enabled wild card mapping for IIS. Only a specific list of extensions are mapped to ASP.NET, others - including 'no extension', simply won't ever reach your code. If this problem occurs when using the VS 2005 development server, then you have a different problem, because the WebDev server always has a wild card mapping enabled.

    Sunday, July 15, 2007 2:05 PM
  • User1473066820 posted

    hi  albert

    thx 4 ur response but when i tried the above line of code it gives compilation error, also the module in the url above doesn't contain url rewriting

    Sunday, July 15, 2007 2:10 PM
  • User1001868398 posted

    What's the compilation error? What line?

    Sunday, July 15, 2007 2:18 PM
  • User1473066820 posted

    hi albert

    it's Compiler Error Message: CS1010: Newline in constant
    and the line is :

    if (app.Request.Url.AbsolutePath.ToUpper().IndexOf("SUBSITES/.+",") > -1 )

     

    Sunday, July 15, 2007 2:29 PM
  • User1001868398 posted

    You had an extra " now looks like that 

    if (app.Request.Url.AbsolutePath.ToUpper().IndexOf("SUBSITES/.+") > -1 )

    Also the sample zips the reply if the page is not aspx or ascx I believe you can change it to check and do a response.redirect

    Sunday, July 15, 2007 2:37 PM
  • User1473066820 posted

    Hi al

    the compilation error has gone but i think the regular expression wasn't the problem coz it works fine with and without the ".aspx", also i need the subsite value (written aflter /subsites/)

    also the page can't be found still exist, i ll check the gzip sample

    thx alot 4 ur help

    Sunday, July 15, 2007 4:01 PM
  • User1473066820 posted

    It's probably because you have not enabled wild card mapping for IIS. Only a specific list of extensions are mapped to ASP.NET, others - including 'no extension', simply won't ever reach your code. If this problem occurs when using the VS 2005 development server, then you have a different problem, because the WebDev server always has a wild card mapping enabled.

    i think that's right,and im using iis 5 on win xp not vs development server, the question now is how to enable wild card mapping with iis 5 for the 'no extension' so that the request to directories reach myy code?

    alos i ve tried : iis manager -> site properties -> home directory -> configuration -> add ... but it requires file extension

    thx

    Monday, July 16, 2007 6:37 AM
  • User-225114762 posted

    Goto IIS MMC applet. Right-click your application virtual directory. Select properties. On the tab 'Virtual Directory', click 'Configuration...'. On the tab 'Mappings" click the Add-button. Browse to the ASP.NET isapi extension, typically c:\Windows\...\v2.0.50727\aspnet_isapi.dll, enter .* as the extension. Uncheck the 'Check that file exists' checkbox. Please note that you may need to move focus back and forth a bit in the dialog to get the 'OK' button to become active due to a bug in the dialog.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2007 8:15 AM
  • User-2007271167 posted

    Goto IIS MMC applet. Right-click your application virtual directory. Select properties. On the tab 'Virtual Directory', click 'Configuration...'. On the tab 'Mappings" click the Add-button. Browse to the ASP.NET isapi extension, typically c:\Windows\...\v2.0.50727\aspnet_isapi.dll, enter .* as the extension. Uncheck the 'Check that file exists' checkbox. Please note that you may need to move focus back and forth a bit in the dialog to get the 'OK' button to become active due to a bug in the dialog.

    I have the same problem. My application is deployed on Windows Server 2003 with IIS 6.0 and I tried the above suggestion but MMC complains that '*' is an invalid extension.

    Is there an easy way of implementing this on my platform?

     Many thanks

    Sean.

    Saturday, July 21, 2007 1:23 PM
  • User-2007271167 posted

    Ok, answered my own question with a bit more research. Used wildcard mapping facility in IIS 6.0. This article explains in case anyone wants to know:

    http://weblogs.asp.net/scottgu/archive/2007/03/04/tip-trick-integrating-asp-net-security-with-classic-asp-and-non-asp-net-urls.aspx

    Sean.

     

    Saturday, July 21, 2007 1:38 PM