网址重写在服务器上不起作用 [英] Url Rewritting not working on server

查看:89
本文介绍了网址重写在服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在使用URL重写.
为此,我在全局文件的application_start()
中编写了以下代码

Hello All
I am using url rewriting.
for this i wrote following code in global file''s application_start()

System.Web.Routing.RouteTable.Routes.Add(
                "post_property", new System.Web.Routing.Route("{property_id}",
                new UserRouteHandler("~/SearchDetail.aspx")));



并在类中将UserRouteHandler方法设置为



and make UserRouteHandler method in class as

public UserRouteHandler(string virtualPath)
    {
        _virtualPath = virtualPath;
    }
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        if (requestContext.RouteData.Values["property_id"] != null)
        {
            var display = BuildManager.CreateInstanceFromVirtualPath(
                            _virtualPath, typeof(Page)) as IUserDisplay;
            if (display != null)
            {
                display.property_id = requestContext.RouteData.Values["property_id"] as string;
                return display;
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
     string _virtualPath;
}



和界面



and a interface

public interface IUserDisplay : IHttpHandler
{
    string property_id { get; set; }
}



我在web.config中添加了



i added in web.config

<httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add name="RoutingModule" type="System.Web.Routing.UrlRoutingModule,                 System.Web.Routing,                 Version=3.5.0.0, Culture=neutral,                 PublicKeyToken=31bf3856ad364e35"/>
</httpModules>



并在searchdetail.aspx
上实现该接口 但是当我重定向它时,它会给服务器404错误

它在本地服务器上工作得很好.
谁能为我提供解决方案.

预先感谢.



and implement that interface on searchdetail.aspx
but when i redirect it it give server 404 error

It works perfectly fine on local server.
Can anyone please provide me solution for this.

Thanks in advance.

推荐答案

modules更改为
<modules runallmanagedmodulesforallrequests="true"></modules>

,看看是否有帮助.


这篇关于网址重写在服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆