Read the id by url and create a new one

On the_Load page, I need to run the code to check the URL format. URLs can have the following formats:

http://www.xyzabc.com/DisplayProduct?ID=230  or

http://www.xyzabc.com/DisplayProduct?ID=230&blahblah or

http://www.xyzabc.com/S(yya4h4rf4gjh5eo4uazix2t055)X(1))/DisplayProduct?ID=230

Whenever the url has an identifier, I want to create a URL in the following format:

http://www.xyzabc.com/DisplayProduct?ID=<the id picked from the url>

Since the code will be run for each page (1500+) on the site, how can I write the best optimized code?

+3
source share
6 answers

something like that:

int ID = 0;

int.TryParse(Request.QueryString["ID"], out ID);

if (ID > 0)
{
    Response.Redirect(String.Format("http://www.xyzabc.com/DisplayProduct?ID={0}", ID));
}
+1
source

Use URLRoutingor use HTTPHandler/HTTPModuleif possible ............

here is the msdn link for this: ASP.NET rewrite url

+2
source

, httpmodule URL

. URL- ASP.NET

+1

HttpModules ,

context.BeginRequest += context_BeginRequest;

and in the context of_BeginRequest you are doing something like:

context.Response.Redirect(..)

This would be a very “raw” solution in which you have several mechanisms for rewriting URLs for ASP.NET, just check Internet / SO for them.

0
source
 Response.Redirect("http://www.xyzabc.com/DisplayProduct?ID=" + Request.QueryString["ID"].ToString().Trim());
0
source

Use the Rewriting Libaray URL and configure it in web.config to avoid extra code.

0
source

All Articles