简体   繁体   English

如何在ASP.Net和IIS6中处理无扩展URL

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

I need a way to write the extensionless urls. 我需要一种方法来编写无扩展名的URL。 My server is a Shared Host with IIS6.0 version 1. Currenty I am using UrlRewriting.Net dll,which supports only on IIS7. 我的服务器是IIS6.0版本1的共享主机。当前,我使用的是UrlRewriting.Net dll,它仅在IIS7上支持。

My original url is abc.xyz.in/Index.aspx?c=comp_Name; 我的原始网址是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 我的虚拟网址是abc.xyz.in/comp_Name.aspx,但我希望它是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. 因此,我不能自己配置IIS或强制管理员对其进行修改。

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. IIS6(及更早版本)中的自定义路由问题在于,默认情况下,除非您要求提供.aspx,.ashx,.asmx文件,否则它们不会调用ASP.Net模块。 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 ). 有一些使用自定义错误的解决方案,该错误会检查您尝试访问的内容,然后显示正确的页面,但这并不是一个很好的解决方案(但是如果您真的想了解更多信息,请查看示例在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. 我的建议是让您的虚拟主机为ASP.Net添加一个通配符映射,以便它处理到您站点的所有传入请求,以便您可以编写适当的路由模块,虽然它们不一定必须这样做,但是在询问中没有任何危害,它可以轻松地在现场进行设置。 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. 如果这是不可能的,那么您可能应该寻找一个可以满足您站点需求的新虚拟主机,而不是使您的站点适应当前的虚拟主机。

Hi you need to write your own HttpModule. 嗨,您需要编写自己的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();
        }
    }
}

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). 如果您刚开始(或者这样做是一种选择),问题就变成您(您的主机)是否在IIS(6或7)上具有ASP.Net 4。

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)... 无扩展名的URL是ASP.Net 4的一部分-这意味着您的ASP.Net站点(您希望无扩展名的URL工作)必须在ASP.net 4(而不是v2.x)上运行...

Hth... 嗯...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM