Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using URL Rewrite in my application.It working but when user enter wrong page name in URL which is not exit in application it should show error message that "Page Not Found". Below is my code

C#
protected void Application_BeginRequest(object sender, EventArgs e)
       {
           // If the requested file exists
           if (File.Exists(Request.PhysicalPath))
           {
               // Do nothing here, just serve the file
           }
           // If the file does not exist then
           else if (!File.Exists(Request.PhysicalPath) && !Request.PhysicalPath.Contains("WebResource.axd"))
           {

               //var x = Request.FilePath.Remove(0);
               string profilename = Request.FilePath.Replace("/", string.Empty);
                 // Get the URL requested by the user
              // string sRequestedURL = Request.Path.Replace(".aspx", "");

               // You can retrieve the ID of the content from database that is
               // relevant to this requested URL (as per your business logic)
               int nId = 0;
               ////// nId = GetContentIDByPath(sRequestedURL); \\\\\

               // The ShowContents.aspx page should show contents relevant to
               // the ID that is passed here
               string sTargetURL = "~/profile.aspx?ProfileID=" + profilename;// +nId.ToString();

               // Owing to RewritePath, the user will see requested URL in the
               // address bar
               // The second argument should be false, to keep your references
               // to images, css files
               Context.RewritePath(sTargetURL, false);

           }
       }

In web config file custom error mode is on.please help me to solve my problem.

Thanks
Posted
Comments
Dholakiya Ankit 2-Aug-13 7:50am    
do customerrors mode to off and show us real error where u stuck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900