我有如下控制器類:如何忽略不會在MVC中實現Icontroller錯誤?
public partial class GenericViewController : Controller
{
public virtual void StoreUrl(string url)
{
Session["URL"] = url;
}
}
我試圖使用jQuery AJAX如下放置到這個方法的調用:
$.ajax(
{
type: "POST",
cache:false,
url: "http://" + baseUrl + "/GenericView/StoreUrl",
data: { url: applicationurl },
error: Error
});
現在,當我觸發Ajax調用我得到的以下錯誤
[HttpException]: The controller for path '/GenericView/StoreUrl' was not found or does not implement IController.
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<BeginProcessRequest>b__2()
at System.Web.Mvc.SecurityUtil.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[TResult](Func`1 func)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我曾嘗試做以下寄存器途徑解決這個問題,但我仍然收到同樣的錯誤
routes.IgnoreRoute("Ignore/");
routes.IgnoreRoute("{*GenericView}", new { GenView= @"(.*/)?GenericView(/.*)?" });
routes.RouteExistingFiles = false;
routes.IgnoreRoute("GenericView/{*pathInfo}");
附加的註釋:此代碼在名爲LookupData的apllication其作爲託管應用程序的IIS網站,網址爲abc.com映射下託管,然後abc.com承載一個應用程序,它確實驗證和abc.com/LookupData將會觸發託管上述代碼的應用程序。 Lookupdata單獨運行時不會拋出此錯誤,但是當通過abc.com進入時,應用程序無法解析GenericViewController。
我不明白我的代碼中的錯誤在哪裏。任何人都可以請建議解決方案?
爲什麼是類偏? – jgauffin 2013-02-19 14:01:25
是否允許控制器POST請求?也許嘗試改變方法「GET」只是爲了看看你得到同樣的錯誤 如果這樣也行不通,問題出在路由中,你能發佈路由定義嗎? – Tallmaris 2013-02-19 14:03:46
@Tallmaris POST和GET都有同樣的問題 除了忽略路由,我還有以下路由定義: routes.MapRoute( 「Default」,//路線名稱 「{controller}/{action}/{id}」,//帶參數的網址new {controller =「Account」,action =「LogOn」,id = UrlParameter.Optional} //參數默認值 ); – 2013-02-19 14:12:09