有没有人见过这个问题?我是一个ASP.NET MVC新手.我有一个使用.aspx和.ascx视图的ASP.NET MVC 3站点.在整个站点中,我使用返回View()或在我的控制器方法中返回View(viewName),它指向相应的aspx/ascx视图.但是,在我的股票AccountController(修改为使用DotNetOpenAuth)中,我采用相同的方法,但MVC框架不寻求aspx或ascx视图.相反,它正在搜索.cshtml或.vbhtml视图的路径(Razor引擎我假设).为什么它只是寻找像我网站其余部分的aspx和ascx视图?控制器方法如下:
public ActionResult Authenticate()
{
var response = openid.GetResponse();
var statusMessage = "";
if (response == null)
{
Identifier id;
//make sure your users openid_identifier is valid.
if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
{
try
{
//request openid_identifier
return openid.CreateRequest(Request.Form["openid_identifier"])
.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
statusMessage = ex.Message;
return View("LogOn", statusMessage);
}
}
else
{
statusMessage = "Invalid identifier";
return View("LogOn", statusMessage);
}
}
else
{
//check the response status
switch (response.Status)
{
//success status
case AuthenticationStatus.Authenticated:
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
//TODO: response.ClaimedIdentifier, to login or create new account
return RedirectToAction("Index", "Home");
case AuthenticationStatus.Canceled:
statusMessage = "Canceled at provider";
return View("LogOn", statusMessage);
case AuthenticationStatus.Failed:
statusMessage = response.Exception.Message;
return View("LogOn", statusMessage);
}
}
return View("LogOn");
}
Run Code Online (Sandbox Code Playgroud)
错误详情如下:
未找到视图"LogOn"或其主节点,或者没有视图引擎支持搜索的位置.搜索了以下位置:〜/ Views/Account /在provider.master上取消〜/ Views /共享/取消在provider.master~/Views/Account/LogOn.cshtml~/Views/Account/LogOn.vbhtml~/Views/shared/LogOn.cshtml~/Views/Shared/LogOn.vbhtml~/Views/Account /在provider.cshtml取消〜/ Views/Account /在provider.vbhtml取消〜/ Views/Shared /在provider.cshtml取消〜/ Views/shared/cancelled在provider.vbhtml
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.InvalidOperationException:未找到视图"LogOn"或其主节点,或者没有视图引擎支持搜索的位置.搜索了以下位置:〜/ Views/Account /在provider.master上取消〜/ Views /共享/取消在provider.master~/Views/Account/LogOn.cshtml~/Views/Account/LogOn.vbhtml~/Views/shared/LogOn.cshtml~/Views/Shared/LogOn.vbhtml~/Views/Account /在provider.cshtml取消〜/ Views/Account /在provider.vbhtml取消〜/ Views/Shared /在provider.cshtml取消〜/ Views/shared/cancelled在provider.vbhtml
来源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[InvalidOperationException:未找到视图'LogOn'或其主节点,或者没有视图引擎支持搜索的位置.搜索了以下位置:〜/ Views/Account /在provider.master上取消〜/ Views /共享/取消在provider.master~/Views/Account/LogOn.cshtml~/Views/Account/LogOn.vbhtml~/Views/shared/LogOn.cshtml~/Views/Shared/LogOn.vbhtml~/Views/Account /在provider.cshtml取消〜/ Views/Account /在provider.vbhtml取消〜/ Views/Shared /在provider.cshtml取消〜/ Views/shared/
cancelled at provider.vbhtml] System.Web.Mvc.ViewResult.FindView(ControllerContext context)+315050
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)+129
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult)+13
System.Web.Mvc.<> c_ DisplayClass1c.b _19()+23 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,ResultExecutingContext preContext,Func1 continuation) +260 System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters,ActionResult actionResult)+177
System .Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String a ctionName)+343 System.Web.Mvc.Controller.ExecuteCore()+116 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)+97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute( RequestContext requestContext)+10
System.Web.Mvc.<> c_ DisplayClassb.b _5()+37 System.Web.Mvc.Async.<> c_ DisplayClass1.b _0()+21 System.Web.Mvc.Async.< > c_ DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult1.End()+ 62 System.Web.Mvc.<> c _DisplayClasse.b_ d()+50 System.Web.Mvc.SecurityUtil.b _0(Action f)+7
System.Web.Mvc.SecurityUtil .ProcessInApplicationTrust(Action action)+22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+9
System.Web.CallHandlerExecutionStep. System.Web.HttpApplication.IExecutionStep.Execute()+8841105 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+184
谢谢山
Jas*_*aat 25
关键是你的例外的第一行:
The view 'LogOn' or its master was not found or no view engine supports
the searched locations. The following locations were searched:
~/Views/Account/Canceled at provider.master
Run Code Online (Sandbox Code Playgroud)
如果将两个字符串传递给View(),则第一个字符串是视图名称,第二个字符串是要使用的主视图或模板的名称.如果要将statusMessage作为视图的模型传递,可以将其强制转换为对象,这会强制调用传递模型的重写View()方法:
return View("LogOn", (object)statusMessage);
Run Code Online (Sandbox Code Playgroud)
您显然正在获取"已取消的提供程序"消息并将其作为要使用的主页面名称传递.如果"Logon.aspx"视图使用了母版页,并且您在共享视图文件夹中有一个主页"在provider.master上取消",则会加载"LogOn.aspx"视图并强制它使用"取消在provider.master"主页面,即使它被设置为默认使用不同的母版页:
string statusMessage = "Canceled at provider";
return View("LogOn", statusMessage);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23036 次 |
| 最近记录: |