We have this web.api-project currently residing in api.mydomain.com. It is as a backend for a mobile app and also a superadminlike javascript application. We also have this new umbraco site (in the same VS-solution) wich currently holds just your plain information (with pages like "about us", "get the app" etc) on www.mydomain.com
We've setup a asp.net membership across theese domains and are now looking to find a way to have the umbraco site host pages like login, edit profile, start subscription etc. The controller(s) for theese views exist in the api-project.
I am not sure what aproach to take. I would preferably be able to use the viewmodels that already exists in the sulution and leverage the whole Modelstate/validation-thing.
We could make our edit profile-forms just to POST to the api-project (CORS is a no go), but then the api project would have to the hackish Request.CreateResponse in order to redirect the user to some hardcoded place back on the umbraco site, right?
It could be very simple: take the logic out of your Web API Controllers and make both your API controllers and new SurfaceController use them (so there's one place where the magic happens and your controllers just use those methods.
Hm, wouldn't that mean that we need to incorporate and configure our Unity (and other structures) in our umbraco-project? Im not the backend guy on this project but pretty sure we are looking to avoid that.
I will have a chat with the backend people though, perhaps they have some thoughts. Maybe something basic such as Logic.PutModel(model) would work...
I'm not sure where Unity came from..? No, this is all default Umbraco stuff.
All I'm saying is if you have:
public class SearchController : UmbracoApiController
{
public List<IPublishedContent> PostSearch(string query)
{
var results = new List<IPublishedContent>();
if (!string.IsNullOrEmpty(query))
{
var helper = new UmbracoHelper(UmbracoContext);
results.AddRange(helper.TypedSearch(query));
}
return results;
}
}
You could extract the logic to something like:
internal List<IPublishedContent> GetSearchResults(string query)
{
var results = new List<IPublishedContent>();
if (!string.IsNullOrEmpty(query))
{
var helper = new UmbracoHelper(UmbracoContext);
results.AddRange(helper.TypedSearch(query));
}
return results;
}
And use default Umbraco Surface Controllers to do form interactions, while executing the same logic in your API Controllers, for example:
public class SearchController : ApiController
{
public List<IPublishedContent> PostSearch(string query)
{
var results = GetSearchResults(query);
return results;
}
}
public class SearchController2 : SurfaceController
{
public ActionResult PostSearch(string query)
{
if (ModelState.IsValid == false)
return CurrentUmbracoPage();
var results = GetSearchResults(query);
return PartialView("Search", results);
}
}
Instead of using strings you'd use your existing models of course.
From what I can gather from the backend guys, we would have to do Unity-hookups in umbraco in order for this suggested solution to work. Having tried doing that previously without success, they are unlikly to try it again I'm afraid. One other suggested solution is to make webapi-calls from a SurfaceController using HttpClient.
The ajax.beginform I assume won't work due to the cross-domain issue. Can give it a shot though. Posting some of the web.api-controller and unityconfig in case it would help you understand their issue:
Ah, okay, here I was assuming that the Umbraco site and the Web API stuff was living in the same solution, guess I was wrong there. Then I'm out of options, sorry. :-)
Umbraco and an external web.api
We have this web.api-project currently residing in api.mydomain.com. It is as a backend for a mobile app and also a superadminlike javascript application. We also have this new umbraco site (in the same VS-solution) wich currently holds just your plain information (with pages like "about us", "get the app" etc) on www.mydomain.com
We've setup a asp.net membership across theese domains and are now looking to find a way to have the umbraco site host pages like login, edit profile, start subscription etc. The controller(s) for theese views exist in the api-project.
I am not sure what aproach to take. I would preferably be able to use the viewmodels that already exists in the sulution and leverage the whole Modelstate/validation-thing.
We could make our edit profile-forms just to POST to the api-project (CORS is a no go), but then the api project would have to the hackish Request.CreateResponse in order to redirect the user to some hardcoded place back on the umbraco site, right?
Thoughts?
What version of Umbraco is this?
It could be very simple: take the logic out of your Web API Controllers and make both your API controllers and new SurfaceController use them (so there's one place where the magic happens and your controllers just use those methods.
For a simple SurfaceController example have a look here (and ignore the webforms part): http://umbraco.com/follow-us/blog-archive/2013/7/14/moving-from-webforms-to-mvc.aspx
Thanks.
Hm, wouldn't that mean that we need to incorporate and configure our Unity (and other structures) in our umbraco-project? Im not the backend guy on this project but pretty sure we are looking to avoid that.
I will have a chat with the backend people though, perhaps they have some thoughts. Maybe something basic such as Logic.PutModel(model) would work...
(Using Umbraco 7.0.1)
I'm not sure where Unity came from..? No, this is all default Umbraco stuff.
All I'm saying is if you have:
You could extract the logic to something like:
And use default Umbraco Surface Controllers to do form interactions, while executing the same logic in your API Controllers, for example:
Instead of using strings you'd use your existing models of course.
The Unity-stuff is part of the other projects in this solution (including the web-api).
I think I understand what you mean. Will look in to it with the team.
From what I can gather from the backend guys, we would have to do Unity-hookups in umbraco in order for this suggested solution to work. Having tried doing that previously without success, they are unlikly to try it again I'm afraid. One other suggested solution is to make webapi-calls from a SurfaceController using HttpClient.
Are we missing something here?
/D
Alright, I have no idea what your setup looks like so I wouldn't be able to comment on that.
You could try and see if Ajax.BeginForm would work?
The ajax.beginform I assume won't work due to the cross-domain issue. Can give it a shot though. Posting some of the web.api-controller and unityconfig in case it would help you understand their issue:
Ah, okay, here I was assuming that the Umbraco site and the Web API stuff was living in the same solution, guess I was wrong there. Then I'm out of options, sorry. :-)
The umbraco site and the web api is in the same VS-solution, but are hosted on diffrent domains. ie www.mysite.com and api.mysite.com.
/D
Just to let you know, we managed to integrate Unity in the umbraco-project this time (with a litlle help from this thread: http://stackoverflow.com/questions/21835555/umbraco-mvc-with-castle-windsor). So it's not really an issue anymore. Thnaks.
is working on a reply...