title: Error with System.Web.Mvc.UrlHelper.GenerateUrl Security Exception
body: <p>I have created an ASP.net MVC 5 application, unfortunately my host is using medium trust. Everything else works when I changed the application from using "~/" to using "/" in url paths. Now my trouble is that the application is throwing an exception in the function System.Web.Mvc.UrlHelper.GenerateUrl() when I am creating a form with the code below:</p>
  
  <pre><code>@using (Html.BeginForm("Index", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
  </code></pre>
  
  <p>The error message is:</p>
  
  <p>The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. </p>
  
  <p>Below is the full stack trace:</p>
  
  <pre><code> [SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral,              PublicKeyToken=b77a5c561934e089' failed.]
  System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; stackMark, Boolean isPermSet) +0
  System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark&amp; stackMark) +31
  System.Security.CodeAccessPermission.Demand() +46
  System.Web.HttpContext.System.IServiceProvider.GetService(Type service) +54
  System.Web.HttpContextWrapper.GetService(Type serviceType) +11
  System.Web.WebPages.UrlRewriterHelper.IsUrlRewriterTurnedOn(HttpContextBase httpContext) +108
  System.Web.WebPages.UrlRewriterHelper.WasRequestRewritten(HttpContextBase httpContext) +13
  System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) +138
  System.Web.WebPages.UrlUtil.GenerateClientUrl(HttpContextBase httpContext, String contentPath) +97
  System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection,      RequestContext requestContext, Boolean includeImplicitMvcValues) +139
  System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, FormMethod method,      IDictionary`2 htmlAttributes) +41
  System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, String actionName, String controllerName, Object routeValues, FormMethod method, Object                htmlAttributes) +58
  ASP._Page_Views_Shared__EnquiryPartial_cshtml.Execute() in d:\inetpub\vhosts\mydomain.com\httpdocs\Views\Shared\_EnquiryPartial.cshtml:16
  System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
  System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
  System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +90
  System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
  System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
  System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection                 viewEngineCollection) +277
  System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +91
  System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName) +32
  ASP._Page_Views_Home_Parallax_cshtml.Execute() in d:\inetpub\vhosts\dmydomain.com\httpdocs\Views\Home\Parallax.cshtml:670
  System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
  System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
  System.Web.WebPages.StartPage.RunPage() +17
  System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
  System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
  System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
  System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
  System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
  System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
  System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext            controllerContext, ActionResult actionResult) +56
  System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext            controllerContext, ActionResult actionResult) +420
  System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass28.&lt;BeginInvokeAction&gt;b__19() +173
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1e.&lt;BeginInvokeAction&gt;b__1b(IAsyncResult asyncResult) +100
  System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
  System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
  System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
  System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
  System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +41
  System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +12
  System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
  System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +31
  System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
  System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +21
  System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
  System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
  System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>
  
  <p>Any help will be appreciated.</p>