.net core 500 internal server error after adding new api controller - asp.net-core

I have created a .net core application which currently has one api controller and everything works fine. The problem is when I add another api controller to the solution with a different name and route. If I try to to run the APIs I get 500 internal server error once I add another controller.
If I remove the newly added api controller everything works fine again.
Any help would be appreciated!

Seems like the problem is with the name (Name = "Get") attribute added to HttpGet method was the problem. All the controllers had the same Name attribute and hence the error. Removing the Name attribute from controllers solved the problem.
[HttpGet("{id}", Name = "Get")]
public string Get(int id)
{
return "value";
}

Related

ERR_HTTP2_PROTOCOL_ERROR when using TempData in ASP.NET Core 6

When I don't use TempData, the page works fine, but when I use it I get the following error.
This site can’t be reachedThe webpage at https://localhost:44332/Home/UploadFile might be temporarily down or it may have moved permanently to a new web address.
ERR_HTTP2_PROTOCOL_ERROR
Here's the code of the controller
TempData["Response"] = responseString;
return RedirectToAction("Index");
Any ideas??

Web API return Helper Page

I have a ASP.NET WebPage and like to use the Helper Pages located under App_Code. Now I don't have any clue how to solve this problem: I post data from a html form to my Controller (WebApi 2 HttpPost method) with $.ajax. As a result, I wan't the content of my helper page, whose binding data comes from my controller web api method.
I would like to maintain my form data encapsulated in my model class, because it seems cleaner to me to handle with the data. I also want to access my model in my view.
[HttpPost]
[Route("api/{ClassID}/AddUsers")]
public IHttpActionResult AddUsers([FromUri] int ClassID, [FromBody] Models.UserInfo userInfo)
{
Foo result = new Foo();
result = doSometStuff(userInfo);
return ???(HelperPages.FooHelper.Get(result));
}
I have to answer my question myself. Web API only returns data, not any view. So I just have to use a mvc controller to do so.

Hook up Auth0AccountController in Umbraco 7

Has anyone successfully integrated Auth0 with Umbraco 7 for member (front-end public users, not CMS back-end users) authentication?
I've successfully integrated with owin startup and dealing with signin-auth0 response. However I'm stuck on hooking up the Auth0AccountController to work with Umbraco (I'm getting a 404). Any suggestions?
I've tried adding ~/Auth0Account to the "umbracoReservedPaths" appSetting, but I just get a slightly different looking 404 (not controlled by Umbraco by looks of it).
I've also tried mapping the route in Startup.cs using
RouteTable.Routes.MapRoute(
"Auth0Account",
"Auth0Account/{action}",
new
{
controller = "Auth0Account"
}
);
but that results in a "No route in the route table matches the supplied values" error.
Any ideas?
Mapping the Auth0Account route in Startup.cs was correct:
RouteTable.Routes.MapRoute(
"Auth0Account",
"Auth0Account/{action}",
new
{
controller = "Auth0Account"
}
);
Turns out my problem was with the default redirect RedirectToLocal method in the Auth0AccountController controller. It was doing a
return RedirectToAction("Index", "Home");
which I didn't have a controller hooked up for. I replaced this with an Umbraco compatible redirect instead.
Also, instead of Auth0AccountController inheriting from Controller it might be useful to inherit from Umbraco.Web.Mvc.SurfaceController or Umbraco.Web.Mvc.RenderMvcController to expose useful Umbraco methods to the code.

Can Umbraco pass a model to view

I am quite new to this Umbraco MVC.
I need to pass some data bound to a model to my partial view from the GET action method.
This simply is not working in a regular MVC way.
[httpget]
public ActionResult Membership()
{
SupplierMembershipInfoModel mm = new SupplierMembershipInfoModel();
mm.ProductPackage = "sssssssss";
ViewBag.status = Request.QueryString["status"];
return PartialView("MembershipPartial", mm);
}
my view:
#model Umbraco.Web.Models.SupplierMembershipInfoModel
some html.....
<td>#Model.ProductPackage</td>
I don't get data here...and the debug never hits the action. But it hits any POST action method.
I know i am doing something wrong...but just don't know what the mistake is??
Any ideas??
As #Sebastiaan points out, the best place to start is the Umbraco community site. There is documentation specific to your issue here: http://our.umbraco.org/documentation/Reference/Templating/Mvc/child-actions
In a nutshell, you want to display a child action on your page and Umbraco uses SurfaceControllers for this. A SurfaceController is simply a Controller that inherits from Umbraco.Web.Mvc.SurfaceController. This provides you Controller with access to the Umbraco context - see here (http://our.umbraco.org/documentation/Reference/Templating/Mvc/surface-controllers).
Either way, you should read the whole documentation section on templating as it will give you a lot of insight into how Umbraco MVC is managed.

Twilio.MVC ValidateRequest on AppHarbor

I am trying to get the twilio.MVC helper attribute ValidateRequest to work on a MVC 4 controller running in AppHarbor. I can't seem to get it to work and I assume it is because my app is running behind a load balancer. I've tried supplying the UrlOverride parameter in the call, but I can't seem to get it correct. Assuming my appharbor app url = myapp.apphb.com, my controller = callhandler, my action = handlecall, how should I be calling the ValidateRequest attribute?
ValidateRequest[("MYAUTHTOKEN","myapp.apphb.com")]
Doesn't seem to work, I constantly get a 403 Forbidden error back.
Just an FYI- I am decorating the individual MVC action and not the entire controller at this point.
In case anybody runs into this same issue, I got this working by specifying the UrlOverride as a Named Parameter along with the controller and the action, like so:
ValidateRequest[("MYAUTHTOKEN", UrlOverride="http://myapp.apphb.com/controller/action")]