gpt4 book ai didi

asp.net-mvc-3 - asp.net mvc3 - Controller 方法返回 View(viewName, string) 但随之而来的是奇怪的情况

转载 作者:行者123 更新时间:2023-12-03 04:20:46 25 4
gpt4 key购买 nike

有人见过这个问题吗?我是 ASP.NET MVC 新手。我有一个使用 .aspx 和 .ascx View 的 ASP.NET MVC 3 站点。在整个站点中,我在 Controller 方法中使用 return View() 或 return View(viewName) ,这会定向到适当的 aspx/ascx View 。然而,在我的普通 AccountController(修改为使用 DotNetOpenAuth)中,我采用相同的方法,但 MVC 框架不会寻找 aspx 或 ascx View 。相反,它正在搜索 .cshtml 或 .vbhtml View 的路径(我假设是 Razor 引擎)。为什么它不像我网站的其他部分那样只寻找 aspx 和 ascx View ? Controller 方法如下:

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");
}

错误详细信息如下:

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 ~/Views/Shared/Canceled at provider.master ~/Views/Account/LogOn.cshtml ~/Views/Account/LogOn.vbhtml ~/Views/Shared/LogOn.cshtml ~/Views/Shared/LogOn.vbhtml ~/Views/Account/Canceled at provider.cshtml ~/Views/Account/Canceled at provider.vbhtml ~/Views/Shared/Canceled at provider.cshtml ~/Views/Shared/Canceled at provider.vbhtml

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: 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 ~/Views/Shared/Canceled at provider.master ~/Views/Account/LogOn.cshtml ~/Views/Account/LogOn.vbhtml ~/Views/Shared/LogOn.cshtml ~/Views/Shared/LogOn.vbhtml ~/Views/Account/Canceled at provider.cshtml ~/Views/Account/Canceled at provider.vbhtml ~/Views/Shared/Canceled at provider.cshtml ~/Views/Shared/Canceled at provider.vbhtml

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: 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 ~/Views/Shared/Canceled at provider.master ~/Views/Account/LogOn.cshtml ~/Views/Account/LogOn.vbhtml ~/Views/Shared/LogOn.cshtml ~/Views/Shared/LogOn.vbhtml ~/Views/Account/Canceled at provider.cshtml ~/Views/Account/Canceled at provider.vbhtml ~/Views/Shared/Canceled at provider.cshtml ~/Views/Shared/Canceled 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, IList
1 filters, ActionResult actionResult) +177
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +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.WrappedAsyncResult
1.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

谢谢山

最佳答案

关键在异常的第一行:

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

如果将两个字符串传递给 View(),第一个字符串是 View 名称,第二个字符串是要使用的主视图或模板的名称。如果您想传递 statusMessage 作为 View 的模型,您可以将其转换为对象,这将强制调用覆盖的 View() method在哪里传递模型:

return View("LogOn", (object)statusMessage);

您显然收到了“已在提供商处取消”消息并将其作为要使用的母版页名称进行传递。例如,如果“Logon.aspx” View 使用母版页,并且您的共享 View 文件夹中有一个母版页“在provider.master 处取消”,则这将加载“LogOn.aspx” View 并强制它使用“即使默认情况下设置为使用不同的母版页,也会在“provider.master”母版页上取消:

string statusMessage = "Canceled at provider";
return View("LogOn", statusMessage);

关于asp.net-mvc-3 - asp.net mvc3 - Controller 方法返回 View(viewName, string) 但随之而来的是奇怪的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5086734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com