I have an action that returns a Dynamically Generated image however I need the call to that action to end with a something.jpg.
This answer is very similar to my action Can an ASP.NET MVC controller return an Image?
MY action takes in a string called ID which I intend to pass the Something.jpg but my problem is that while this works locally when I deploy to my server and try it I get an IIS 7 404 error.
It looks like IIS is trying to find the final rather than calling the action, at no point is the action called.
I've tried adding the following to the global.asax to force it to call the action but to no avail.
routes.RouteExistingFiles = true;
routes.IgnoreRoute("Content/{*pathInfo}");
Could it be an issue with Mime types?
You may need to set your IIS 7 Application Pool in Integrated mode.
Related
1.I have tried adding the IIS Rewrite Rule which works for local environment but not in the higher environments.
2.Sitecore redirect settings is also not working.
3.Currently (localhost)/default loads the homepage and I need this to get redirected to another page of my site.
Can somebody help me to achieve this without overriding the HttpBeginRequest Processor?
public IActionResult Privacy(){return Redirect("https://google.com"); }
As you have an MVC project, requests will all route to a controller action, you can set the redirection in the corresponding action.
I am working on an email program for a WordPress WooCommerce store. I have added a webhook into the WooCommerce settings in order to hit a C# WebAPI application that I have created. I am trying to get run an email process every time an order is created.
I created an API controller with that accepts the JSON data that is sent over from WooCommerce, and when testing it locally from a Postman request, the controller is hit no problem.
I am trying to publish the application on Azure, and when I do, I am getting a 400 error from both the WooCommerce settings as well as any Postman requests.
I have tried setting
<system.webServer>
<httpErrors existingResponse="PassThrough"/>
</system.webServer>
in the web.config file, which then returned a 502 error from Postman, but still the same error on the WooCommerce webhook side.
I also tried re-deploying which did not work either.
I am able to view the homepage as well as the API controller link on the standard MVC homepage/menu view.
The controller is a standard API controller inheriting from the APIController class:
public class OrdersController : ApiController
and it contains one method, ProcessOrders, with an [HttpGet, HttpPost] attribute on it, and a route of /api/orders/callback.
The controller is responsible for inserting the payload from the webhook into the database and then it uses some other classes email out some specific information about the product.
Is there some kind of setting that needs to be set in the Azure portal or on the web.config file? I am not very experienced with Azure so I am not too familiar if there is anything else that needs to be done for this.
Azure Information
I am deploying to azure from quick publish inside Visual Studio
A Pay-As-You-Go resource group
.Net Framework version 4.7
Remote debugging enabled
Web App app service
The only App service setting is WEBSITE_NODE_DEFAULT_VERSION set to 6.9.1
I have tried both Release and Debug configurations, the connection is valid when trying the Validate Connection option inside configuration, the File Publish Options are all unchecked (Remove additional files at destination, precompile during publishing, exclude files from app_data folder) and the publish works fine, and the app is accessible, except for the api controller.
The project is built as a .Net framework version 4.6.1 with Web API.
Thanks in advance for any help!
Edit
I have removed the parameter that was part of the original method that is being hit by the API, and I am now getting the error of No HTTP resource was found that matches the request URI. I have tried changing the Route data annotation as well as just making it HttpGet to see if it was accessible, and it is not working. I created a second action on the controller just to test returning a string, and that worked without problem, so I am not sure why it is not accessible. The intro to the method is as follows:
[HttpGet]
[Route("api/orders/callback")]
public string Callback() { return "Test"; }
I also updated this method to try just returning a simple string and it does not work. I also adjusted the second test method to accept a string POSTed to it and it is returning The requested resource does not support http method 'POST'.
This method looks like the following:
[HttpPost]
[Route("api/orders/new")]
public string SecondCallback(string payload) {
return payload;
}
I am working on an application which uses a Web Service. This web service uses the MVC Framework for .NET.
In the web service, I added extra parameters to a method in the controller, and therefore changed the Global.asax.cs file to add those parameters to the specific method's route. However, when I run the application now, I get the error:
ArgumentException was unhandled by user code: An item with the same key has already been added.
I did not create another MapRoute, I just updated the existing MapRoute for that specific method to have extra parameters.
Do I have to do anything else with the routing or another file after I change the number of parameters in a method in the controller?
Why would I be getting a same key issue when there is only one MapRoute to that method name?
I just recently got a fresh install of Windows 7 on a my PC running VS2012/VS2010. I have an MVC3 project that ran just fine before I pulled it onto this PC to run. The project still compiles on this PC and I can navigate through my site while running the app in studio (2010 or 2012), but when I tried to POST from ANY form in ANY view and pass an ID by means of the URL like this:
<form id="ScriptForm" action="/MyApp/ControllerName/ActionName/#ViewBag.IDNumber" method="post">
...
</form>
...I got this error. I did some digging and playing around to try to fix this, ultimately taking these steps to try to resolve:
Actually installed ASP.NET via the Windows Components form in Control Panel
Changed the application to use IIS Express
Well, when I changed it to run under IIS Express, I started getting a different error.
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is
temporarily unavailable.
Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.
Things you can try:
Create the content on the Web server.
Review the browser URL.
Check the failed request tracing log and see which module is calling SetStatus. For more information, click here.
Detailed Error Information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://localhost:51596/MyApp/ControllerName/ActionName/1
Physical Path C:\CODE\MyApp\ControllerName\ActionName\1
Logon Method Anonymous
Logon User Anonymous
Request Tracing Directory C:\Users\cbarlow\Documents\IISExpress\TraceLogFiles\MYAPP
More Information:
This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
View more information ยป
It's almost as if it is not recognizing that this is a route and is trying to resolve the URL to a physical file (like 1.html) which obviously does not exist. But why isn't it "doing the MVC thing" and using the route? I have this in my global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
And I know this is running because I can breakpoint it.
Specs:
Windows 7 | Visual Studio 2010/2012 | Microsoft MVC3 | IIS Express
I've read all these SO posts, none seem to apply in this situation or do not help (mostly, because they apply to actual aspx pages, where I am trying to load pages via controllers):
The HTTP verb POST used to access path '/' is not allowed
The HTTP verb POST used to access path is not allowed
The HTTP verb POST used to access path '/Membership/user/' is not allowed
The HTTP verb POST used to access path '/Main/[object Object]' is not allowed
The HTTP verb POST used to access path '[my path]' is not allowed
HTTP verb POST used to access path '/' is not allowed in Facebook app
Any ideas?
The problem is here (due to my lack of experience with MVC/CSHTML):
<form id="ScriptForm" action="/MyApp/ControllerName/ActionName/#ViewBag.IDNumber" method="post">
...
</form>
The MyApp used to work on my PC (I'm honestly not sure why it doesn't work now... maybe I had set something up for that name to resolve before?) but it no longer maps to anything. It DOES work on the server, but that's because there is indeed a mapping for "MyApp" in IIS. Simply changing this form to this:
<form id="ScriptForm" action="#Url.Content("~/ControllerName/ActionName/" + ViewBag.IDNumber)" method="post">
...
</form>
...does the job more elegantly and without errors.
Sometimes when I launch my MVC 3 project it attempts to load the fully qualified URL for the view being rendered instead of the action within the controller (Which gives me a 404 error). Other times it works fine and actually hits the controller action like it's supposed to, but it's about 50/50.
The URL it hits sometimes is: http://localhost:xxxx/Views/Account/LogOn.cshtml
Here is the default route setup in the Global.asax file:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);
I also tried removing the /{id} parameter from the route as I don't feel it's needed for the logon screen.
Any ideas? Currently the project is setup pretty simply with the default action method LogOn in the AccountController etc. The only thing I did was change the controller and action in the global.asax file.
Try this :go to Project Properties > Web > Start Action
And check the Specific Page option - leaving the text box blank.
You are probably using Visual Studio and you probably are actively editing a .cshtml page when you hit debug.
Try launching the debugger when you are either looking at a code file or a file from a project that isn't in the startup project (ie, your EF/model project) and see if that launches the debugger to the correct URL.
There might be a setting in the project properties that specifies the startup URL. I'll look for it and edit this post if I find it.
I'm guessing you using cassini (builtin dev web server in VS.Net)? If so I get this all the time and seams to be a bug in VS.Net. Switch to IIS 7.5 and you don't get it any more