Hi. i show articles names on default.aspx. when i click an article's nam, it will redirect to detay.aspx. i send info using querystring.
response.redirect(""detay.aspx?id="+artid+"&name="+artname);//artid is id of article and rtname is header of article.
i want this url to show like ../detay/{articlename}. for doing this, i try httphandler. but it gives error. My codes are:
public void ProcessRequest(HttpContext context) { string path = context.Request.Path; int ind = path.LastIndexOf('.'); string newpath = path.Substring(0, ind ); string detayadi = context.Request.QueryString["adi"]; newpath = newpath + "/" + detayadi; context.RewritePath(newpath); IHttpHandler hnd = PageParser.GetCompiledPageInstance(newpath, null, context); hnd.ProcessRequest(context); }
|
this is my httphandlr code. Request.QueryString[
"adi"] is header of article.
in webconfig:
<httpHandlers> <add verb="*" path="*/detay.aspx" type="MyHandler.UrlHandler,MyHandler" validate="true"/>
httpHandlers>
|
i added this. it give error like url doesn't find. how can i do this?Thanks.
sadiPosted Jan 4, 2011, 9:35 AM
Please change the path in config as following:
path="*/detay/*"
In my machine it is working when i use url http://localhost:62078/detay/article1
and alsoi tried project you sent me.but i couldn't run on my computer.
Thanks again.
Jean PaulPosted Jan 4, 2011, 8:44 AM
You can try my web app attachment.
or
Give your sample project.. i will fix it.
sadiPosted Jan 4, 2011, 8:34 AM
Line 8:
Also, Thanks for replies.
Jean PaulPosted Jan 4, 2011, 7:40 AM
handler.Detay,DetayIt is always namespace.type,assemblynamesadiPosted Jan 4, 2011, 4:37 AM
<%@ WebHandler Language="C#" Class="handler.Detay" %>
using System;
using System.Web;
using System.Web.UI;
using System.Web.Services;
namespace handler
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Detay : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string path = context.Request.Path;
int ind = path.LastIndexOf('.');
string newpath = path.Substring(0, ind);
string detayadi = context.Request.QueryString["adi"];
newpath = newpath + "/" + detayadi;
context.RewritePath(newpath);
IHttpHandler hnd = PageParser.GetCompiledPageInstance(newpath, null, context);
hnd.ProcessRequest(context);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
also web.config is set as you said. it gives error:
Could not load file or assembly 'handler' or one of its dependencies. Sistem belirtilen dosyayi bulamiyor.
Source Error:
Jean PaulPosted Jan 4, 2011, 4:03 AM
sadiPosted Jan 4, 2011, 3:45 AM
Jean PaulPosted Jan 4, 2011, 2:58 AM
Please change the path in config as following:
path="*/detay/*"
In my machine it is working when i use url "http://localhost:62078/detay/article1"
Regards,
Jean Paul