1

I have a custom handler I've written that executes a custom action based on a parameter, for example:

/action/option1

would execute the action handler with option1. I can have any number of options for the parameter...

however this action is a custom handler, NOT an mvc controller, because I'm returning a plain text (possibly moving to a json response in the future) not an html page.

how can I route urls of that format to run through the custom handler, passing the option as a parameter? I though of using the iis7 url rewrite, which sounds ideal but I didn't know if there was a better option...

thanks!

1 Answer 1

2

Even if you're just returning text you should still do it via controllers and actions. Your action should just return a ContentResult instead of a ViewResult. That way you still get the built in routing and you can just change it later to return a JsonResult if needs be.

Sign up to request clarification or add additional context in comments.

2 Comments

neat! I didn't know there was such a thing. so are httphandlers discouraged in mvc?
I think it's generally encouraged to use ActionResults wherever possible. There's a whole set of different classes that derive from it, it's not just views, text and json either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.