0

Previously I had url as below:

http://xyz.in/Modules/kOPYWOeJHOjPM04ejG%2faRA%3d%3d

and it used to give me error saying resource not found (because %2f in url, it is getting decoded by MVC), but when I do it like below:

http://xyz.in/Modules/id=kOPYWOeJHOjPM04ejG%2faRA%3d%3d

(added id= before parameter value) then it works fine.

I want url to work without mentioning id (parameter name). Can I even achieve it?

Update:

Routing rule is as below:

routes.MapRoute(
    name: "Modules",
    url: "Modules/{id}",
    defaults: new { controller = "Modules", action = "Modules", id = UrlParameter.Optional }
);

and controller code:

public class ModulesController : Controller
{
    public ActionResult Modules(string id)
    {
        var topic = new Topic();
        return View("Modules", topic.GetTopicWithModules(HttpUtility.UrlDecode(id)));
    }
}
Imad
  • 7,126
  • 12
  • 55
  • 112
  • 1
    Yes, show us the route configuration and the action method on your controller. –  Jul 12 '19 at 16:34
  • I assume that you are facing the issue regarding the routing rules defined in RouteConfig.cs. You can achieve tour desired result if you could define a new specific route. Could u please provide some of your codes – Mahyar Mottaghi Zadeh Jul 13 '19 at 05:15
  • @Amy I have updated my question as sugested, thanks. – Imad Jul 13 '19 at 06:32
  • @MahyarMottaghiZadeh I have updated my question as sugested, thanks. – Imad Jul 13 '19 at 06:32
  • `defaults: new { controller = "Modules", action = "Modules", id = UrlParameter.Optional }` --> your mapping is for an ACTION called Module, but your controller action you seem to expect to hit is Topics. I assume you meant `defaults: new { controller = "Modules", action = "Index", id = UrlParameter.Optional }` with an Index action. – Tieson T. Jul 13 '19 at 07:28
  • @Imad did you check the issue with the url not containing %2f ? – Mahyar Mottaghi Zadeh Jul 13 '19 at 09:10
  • @MahyarMottaghiZadeh Yes I did, and it works fine – Imad Jul 13 '19 at 12:23
  • So cant you create a custom convention in order to prevent the creation of %2f? – Mahyar Mottaghi Zadeh Jul 13 '19 at 12:31
  • @MahyarMottaghiZadeh That would dangerous I guess because this string is a result of encryption and it would break sometime for sure. – Imad Jul 13 '19 at 12:33

0 Answers0