I would like to rewrite all the urls in my project. I am doing it with the help of HttpModule. Its working fine without any query string. But in some pages query string is essential. So can't avoid it. This is the way I've written my HttpModule.
HttpApplication MyApp = (HttpApplication)sender;
string MyOldPath = MyApp.Request.Path;
switch (MyOldPath.ToLower())
{
case "/profile":
OriginalURL = "~/Modules/UserMgmt/Users.aspx?self=true";
break;
default:
break;
}
if (OriginalURL != string.Empty)
MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty);
When I proceed this I got the error " Illegal characters in path"
Then I updated my webConfig as shown below
<system.web>
</httpModules>
<httpRuntime requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" requestPathInvalidCharacters="<,>,*,%,:,&,\" />
</system.web>
At that time the " Illegal characters in path" error solved and getting the Http 404 Error.

I could see the current url when debugging as shown below
If I am not using any url rewrite its url as shown below
Could you help me to solve this issue. Thanks in advance.
Here is the solution....Instead of writing the query string along with the original path, passes it to the third parameter of context.Redirect method. ie) MyApp.context.Redirect(OriginalPath,string.Empty,myQueryString).
The syntax of context.Redirect with three parameter is
RewritePath(String, String, String)
and its meaning is Rewrites the URL by using the given path, path information, and query string information. Reference: https://msdn.microsoft.com/en-us/library/system.web.httpcontext.rewritepath(v=vs.110).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With