Razor behaving diffrent on live server then test server
Hello i am currently developing a ASP.NET MVC 3 application that uses the new razor view engien. But i am having some problem that dose not accrue when i test the homepage in Visual Studio 2010.
Example one of my pages have the following code
Line 37: <div class="info">
Line 38: <a href="@LinkHelper.DisplayProfileUrl((int)Model.Album.User.Id, Model.Album.User.Username)">@Model.Album.User.Username</a>
Line 39: @if (UserHelper.IsModeratorOrAdministrator(Model.Album.UserId)) { <text>(<a href="@LinkHelper.AlbumEditUrl(Model.Album)">Manage Album</a>)</text>}
Line 40: </div>
Give the following error on line 39
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.FormatException: Input string was not in a correct format.
Now in Visual Studio 2010, dose this error not accrue, even with the same data. i have even tryed putting a (int) in front of Model.Album.UserId I do not understand why i am having this error, or how to fix it.
Call stack:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12630485
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +224
Cosplay.Helpers.UserHelper.GetUserId() in C:\CosplayTFS\Website\Branches\Albums\Cosplay\Helpers\UserHelper.cs:50
Cosplay.Helpers.UserHelper.IsModeratorOrAdministrator(Int32 userId) in C:\CosplayTFS\Website\Branches\Albums\Cosplay\Helpers\UserHelper.cs:36
ASP.<>c__DisplayClass5.<Execute>b__4() in c:\Server\Web\Kasper\test.cosplay.dk\Views\Albums\AlbumDetails.cshtml:39
System.Web.WebPages.<>c__DisplayClassb.<RenderSection>b__9(TextWriter tw) +289
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Server\Web\Kasper\test.cosplay.dk\Views\Shared\_Layout.cshtml:61
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
System.Web.WebPages.Web开发者_开发问答PageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +173
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +234
System.Web.WebPages.WebPageBase.PopContext() +234
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
The functions
public static bool IsAuthenticated()
{
return HttpContext.Current.User.Identity.IsAuthenticated;
}
public static bool IsModeratorOrAdministrator(int userId)
{
if (!IsAuthenticated())
return false;
return GetUserId() == userId || (Roles.IsUserInRole("Moderator") || Roles.IsUserInRole("Administrator"));
}
public static int GetUserId()
{
int tryp;
if(!int.TryParse(HttpContext.Current.User.Identity.Name, out tryp))
return -1;
return tryp;
}
My first thought is that it isn't a problem with the view engine. Given the System.FormatException
, I would double check the values for either the Model.Album.UserId
argument for the IsModeratorOrAdministrator
method, or the Model.Album
argument for the AlbumEditUrl
method.
Wild guess... you have different web.configs between the two and the one on the server hasn't registered the namespace in which UserHelper and/or LinkHelper is defined.
精彩评论