last day (15 days later) » 

6:08 PM
1
Q: MVC Controller not firing

tnwI'm trying to set up a routing controller to intercept get requests for particular files when the browser caches them on app startup. I can see the request in the console coming in: Application Cache Progress event (275 of 472) http://mywebsite.com/Path/Whatever/App/Views/SubFolder/Reports/So...

 
Most likely the order of your routes is incorrect. Please show all your MapRoutes code.
 
tnw
@ErikPhilips Posted the rest of the code. It's the only route I have defined actually.
@kaveman I'll add a string parameter to GetReport and see what happens.
 
The problem is the .html (period in the path) try removing it from your request, and I bet it will hit the controller.
 
tnw
@kaveman That's literally the only thing in ReportsController other than the class/namespace declaration. Adding rest of Application_Start() code in Global.asax.
@ErikPhilips Removed the .html from the offline manifest, request came in without .html, and the controller was still not fired. Resulted in a 404.
 
What version of MVC (3,4,5)?
 
tnw
6:08 PM
Appears to be 4.0 if I'm reading this correctly: <assemblyIdentity name="System.Web.Mvc" publicKeyToken="xxxxxxxxxxxx"/> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
 
And your controller is public (not internal)?
 
tnw
@ErikPhilips Yep, the controller is public.
Hi Erik
 
Hello
This is very odd
It's something basic
nothing to do with your controller or url
something odd in the maproute
 
tnw
Yeah
Im totally new to writing controllers but this seems like it should be pretty straight forward
Its the only path I have mapped
Just to explain a bit of context
There's a push for being able to update these html pages without having to redeploy the app/modify anything in the virdir
 
wait
 
tnw
6:12 PM
so I'm trying to intercept the cache request for those particular pages and serve up these html pages from a different location
 
you don't need any controllers/maproutes if you are actually serving html files that exist on the webserver
Ok..
 
tnw
they arent on the webserver ,thats the point :)
 
(ps use a FileResult, they are very very fast)
 
tnw
Thank you :)
So yeah just for the scope of the question, just trying to get that method in that controller to fire
when I request .....Reports/whatever
 
(i'm testing some stuff)
also for testing you can always return new EmptyResult()
so you don't have to actually have a view
the result is an empty page
but not a 404
 
tnw
6:18 PM
Hmph
Okay
 
Testing, I think I figured it out
quite funny actually
if I'm right
 
tnw
I would love to hear haha
And I hope you are
Forehead bleeding and hair missing...... I'm sure you know how it goes
 
Ok as I suspected
I recreated your application
namespace WebApplication3.Controllers
{
    public class ReportsController : Controller
    {
        // GET: Reports
        public ActionResult GetReport()
        {
            return new EmptyResult();
        }
    }
}
 
tnw
2 differences I can spot -- no param of getreport, setting (optional) id parameter
 
namespace WebApplication3
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "blah",
url: "Path/Whatever/App/Views/SubFolder/Reports/{report}",
defaults: new { controller = "Reports", action = "GetReport" }
);

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
WTF is wrong with this code GDI
 
tnw
6:25 PM
Yeah its freaking on my screen
 
http://localhost:12145/Path/Whatever/App/Views/SubFolder/Reports/test = 200
http://localhost:12145/Path/Whatever/App/Views/SubFolder/Reports/test.html = 404
 
tnw
I tried removing the .html from my cache manifest
when the request comes in for /test it gets a 404
 
yeah so something else is wrong
can you post the full controller file code here?
it doesn't need to be formatted
 
tnw
public class ReportsController : Controller
{
//So y
// GET: /Reports/

public ActionResult GetReport(string report)
{
using (StreamWriter sw = System.IO.File.AppendText(@"C:\Users\myusername\Desktop\controller.txt"))
{
sw.WriteLine("controller fired at " + DateTime.Now.ToString());
}

return new EmptyResult();
}

}
 
what namespace is it in
PS if you're using the streamwriter only for debugging, you should instead use Debug.WriteLine()
 
tnw
6:28 PM
let MyNamespace be the same namespace global.asax and routeconfig.cs are contained in
just the base namespace of the project
controller is in MyNamespace.Controllers
er
.Controller
no im dumb
.Controllers, first was right
 
I can't reproduce your problem, something is missing. I doubt it's because I'm using MVC 5
 
tnw
yea not likely
Humph
 
wait
omg
no no
 
tnw
I'm running this on local IIS, not the VS dev server if it makes a difference
 
if the streamwriter failed (in any way) you should get a 500
 
tnw
6:35 PM
Yeah I get a 404 though
 
Yeah I thought maybe the streamwriter couldn't write
comment it out for a moment
 
tnw
Will do
the other writes in the project havent had any problems
so i doubt it
but I'll try
 
yeah shouldn't make a difference
honestly
 
tnw
404 :(
 
I don't know what I can do to help at this point.
All I can really suggest is to create a new project from scratch with just the bare minimum.
 
tnw
6:47 PM
Yeah, I understand. Thanks kindly for your help man
Much appreciated :)
 
Sure thing, good luck!
 

last day (15 days later) »