Writing SEO friendly url gets infinite loop asp net

0 votes

I am trying to write SEO friendly URL for my website. i am using  global.asax. 

protected void Ap

But When the regular expression matches, the code goes on infinite loop. When I apply debugger in this code, It moves infinitely when the regular expression Matches.
This is the code that I have used 
protected void Application_BeginRequest(object sender, EventArgs e)
    {

        HttpContext incoming = HttpContext.Current;
        string oldpath = incoming.Request.Path;
        string imgId = string.Empty;
        //   string imgName = string.Empty;
        Regex regex = new Regex(@"N/(.+)", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
        MatchCollection matches = regex.Matches(oldpath);

        if (matches.Count > 0)
        {

            imgId = matches[0].Groups[1].ToString();
            // imgName = matches[0].Groups[2].ToString();
            string newPath = String.Concat("~/inner.aspx?Id=", imgId);
            incoming.RewritePath(String.Concat("~/inner.aspx?Id=", imgId), false);
        }

    }
Feb 10, 2022 in Others by Kichu
• 19,040 points
817 views

1 answer to this question.

0 votes
you should know that regex avoid cases  thus n is caught before the first /.

You need either to get the last n and everything that is not /:

Regex regex = new Regex(@"N/([^/]+)$", RegexOptions.IgnoreCase);
Or, use a case sensitive search:

Regex regex = new Regex(@"N/(.+)");
answered Feb 11, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

nginx clean url with seo friendly file names

server {     listen 80;     server_name example.com;     root   /full/server/path/to/your/cms;     index  index.php;     location / ...READ MORE

answered Feb 14, 2022 in Others by narikkadan
• 63,600 points
993 views
0 votes
1 answer

Generator URL Friendly SEO PHP with .htaccess

Options +FollowSymLinks -MultiViews RewriteEngine on RewriteBase / # skip all ...READ MORE

answered Feb 14, 2022 in Others by narikkadan
• 63,600 points
4,476 views
0 votes
1 answer

Can an "SEO Friendly" url contain a unique ID?

beware you can get penalised for duplicate ...READ MORE

answered Feb 17, 2022 in Others by narikkadan
• 63,600 points
556 views
0 votes
1 answer

Laravel 8 routes to controllers. SEO friendly URL structure

use regex to match the slugs  again use ...READ MORE

answered Feb 17, 2022 in Others by narikkadan
• 63,600 points
1,486 views
0 votes
1 answer

Authenticate on an ASP.Net Forms Authorization website from a console app

Essentially, we need to record a regular ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
955 views
0 votes
0 answers

How to get Bitcoin value for corresponding USD value in ASP.NET C#?

I want to get the Bitcoin value ...READ MORE

Mar 1, 2022 in Blockchain by Soham
• 9,710 points
828 views
0 votes
0 answers

The request was aborted: Could not create SSL/TLS secure channel

When I connect to an  HTTPS server ...READ MORE

May 1, 2022 in Other DevOps Questions by Kichu
• 19,040 points
2,028 views
0 votes
0 answers

No connection could be made because the target machine actively refused it?

 I was doing HttpWebRequest to a WebService ...READ MORE

May 5, 2022 in Others by Kichu
• 19,040 points
2,837 views
0 votes
1 answer

Is the single page app in asp.net MVC 4 examples, "Big Shelf", SEO friendly?

the pages that render on the basics ...READ MORE

answered Feb 20, 2022 in Others by narikkadan
• 63,600 points
454 views
0 votes
1 answer

PHP Convert String to SEO Friendly Url For Bengali Language Type

$string = preg_replace("/[^a-z0-9]/u", "$separator", $string);  change the ...READ MORE

answered Feb 14, 2022 in Others by narikkadan
• 63,600 points
1,148 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP