2
votes

I was just assigned to implement one functionality in project that uses Umbraco. My job is to basically generate specific XML and return it to user. However i cannot get it to work, because when i create new controller (i've tried creating

Controller, RenderMvcController and SurfaceController

) and method in it (also if i just create new method in existing controller), i get error 404 after typing url into browser. Example: I create TestController and method Index in it. I've tried combinations where TestController was derived from RenderMvcController or SurfaceController or just Controller. After compiling, etc. when i run

http://my_address/Test 

or

http://my_address/Test/Index

i get 404 error from umbraco. I looked at another pages in umbraco that were already in project and they all are also configured somehow in umbraco web panel:

http://my_address/umbraco

I aslo tried adding new methods to existings controllers, but no luck (again 404 errors). I've never worked with umbraco and i don't know how to configure it. I just want to know if there is any way to create method which will be accessible at:

http://my_address/MyMethod

or

http://my_address/MyController/MyMethod

and would return just exactly what i will program it to (without any Views, Partial Views, etc. - i can set Headers and ContentType manually and my content is pure text) in an existing Umbraco project without having to deal with umbraco admin panel?

Thanks for any help :)

//Edit

My mind is officially blown... My response is culture dependent (i mean i pull different data from db depending on country), but it's not as simple as

CurrentCulture.CultureInfo

Umbraco is configured to return different culture based on domain extension (Germany for .de, Great Britain for .co.uk, and Dennmark for .dk - it's just a manual configuration in umbraco admin panel assigning different culture info and views to different hostnames). Regular controllers get this modified culture from

RenderModel.CurrentCulture

passed as argument to controller's method. Is there a way to create umbraco controller/method/anthing that will not have layout/model assigned to it (so i can display pure XML data i receive from external service) and still have access to umbraco's RenderModel's culture? What i am trying to create is if user types url:

http://my_address.de/myController/myMethod

my controller will get current culture, call external service passing culture as parameter and display received data without wrapping it in any views. Example:

public class myController : SomeBaseUmbracoControllerOrsomething
{
    public string/XmlDocument/ActionResult myMethod(RenderModel model)
    {
        int countryId = myFunctionToTranslateCultureToCountryId(model.CurrentCulture);
        return MethodThatCallsExternalServiceAndReturnsXml(countryId);
    }
}

Sorry for confusion, but i've learned about this whole mess with countries just now...

1
If you create SurfaceController you get to it by typing http://my_address/umbraco/surface/yourcontroller/youractionDavor Zlotrg

1 Answers

2
votes

You don't want to use

  • controller, because this is not picked up by umbraco routing process
  • you don't want to use RenderMvcController, because this is overkill
  • you don't want to use Surfacecontroller because you are not using a Child action or form.

What you need is a UmbracoApiController (http://our.umbraco.org/documentation/Reference/WebApi/) or is your umbraco version is PRE 6.1 then use /Base extention (http://our.umbraco.org/documentation/Reference/Api/Base/Index)

Or if you really want to skip ALL umbraco magic for a certain route, add the path to the web.config/AppSettings/umbracoReservedUrls.