Tuesday, February 8, 2011

Trailing slash at the end of aspx page name

so many days in searching and so many days without a solution a long running problem at my end but finally I found a solution.

the problem is actually when you append a slash at the end of any aspx page it does not generate 404 rather it display same page without any CSS or images because not IIS treat this a folder rather than as a page. however there no clear way resolve this issue. and the SEO people were shouting and make noises as usual that their page rating is going down due to mutiple page with same content means let say

aboutus.aspx

aboutus.aspx/

and

aboutus.aspx/default.aspx

are three wrong pages with same content. so resolve this issue with the help of pageinfo variable, if there is any request which has some pageinfo then redirect it to same url without page info in global.asax see following code snippet.

public void Application_BeginRequest(object sender, EventArgs e)

    {

if (!String.IsNullOrEmpty(Request.PathInfo))

        {

            Response.Redirect(Request.RawUrl.Remove(Request.RawUrl.LastIndexOf("/")));

        }

//throw new HttpException(404,"File not found.");

    }

http://msdn.microsoft.com/en-us/library/system.web.httprequest.pathinfo.aspx#Y280

No comments:

Post a Comment