How to deal with extensionless Url in ASP.Net and IIS6

こ雲淡風輕ζ 提交于 2019-12-12 03:34:31

问题


I need a way to write the extensionless urls. My server is a Shared Host with IIS6.0 version 1. Currenty I am using UrlRewriting.Net dll,which supports only on IIS7.

My original url is abc.xyz.in/Index.aspx?c=comp_Name; My virtual url is abc.xyz.in/comp_Name.aspx but i want it as abc.xyz.in/comp_Name

Is it possible via any other module or anything. Please note mine host is shared host. So I cant either configure IIS on my own or force my admin to make modifications for the same.


回答1:


The problem with custom routing in IIS6 (and older versions) is that they by default doesn't invoke the ASP.Net module unless you are asking for a .aspx, .ashx, .asmx file. There are some solutions to this that use a custom error that checks what you were trying to visit and then shows the correct page but it isn't a very nice solution (but if you really want to read more about it there is a sample over at CodeProject: http://www.codeproject.com/Articles/44475/IIS-vs-ASP-NET-URL-Rewriting).

My suggestion would be to ask your webhost to add a wildcard mapping for ASP.Net so that it handles all incoming requests to your site so you can write a proper routing module, they might not have to but there is no harm in asking and it can easily be set up on a site basis. If that is out of the question then you should probably look for a new webhost that can accommodate the needs for your site instead of adapting your site to your current webhost.




回答2:


Hi you need to write your own HttpModule. This is a good example (it is from here): Have a look on that site, it will describe all steps needed.

using System;
using System.Web;


public class DavModule : IHttpModule {

    private HttpApplication context = null;

    public void Dispose() {
        context.BeginRequest -= new EventHandler(context_BeginRequest);
    }

    public void Init(HttpApplication context) {
        this.context = context;
        this.context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void context_BeginRequest(object sender, EventArgs e) {
        HttpApplication app = (HttpApplication) sender;
        app.Response.ContentType = "text/plain";

        if (app.Request.Path.EndsWith("Help"))
            app.Server.Transfer("Help.aspx");
        else {
            app.Response.Write("Path: " + app.Request.Path);
            app.Response.End();
        }
    }
}



回答3:


If you are starting out (or if doing so is an option), the question becomes whether or not you (your host) have ASP.Net 4 on IIS (6 or 7).

Extensionless urls are part of ASP.Net 4 - which means your ASP.Net site/s (that you want to have extensionless urls working) have to be running on ASP.net 4 (not v2.x)...

Hth...



来源:https://stackoverflow.com/questions/10788985/how-to-deal-with-extensionless-url-in-asp-net-and-iis6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!