网址重写在服务器上不起作用
问题描述:
大家好
我正在使用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>
,看看是否有帮助.