Check if url contains text in C# (asp.net 6)

Question: How do you check if Url in the Asp.net MVC has a certain value or text?

Answer: Follow the steps below:

1. Make sure you are using the following Namespace in your Views
     @using Microsoft.AspNetCore.Http

2. In your View or a Layout type

  @if(this.Context.Request.Path.Value.Contains("/myText")){

//Do some Magic

}


Edit this Article
Check if url contains text Asp.Net 6 MVC url check .NET 5 published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy