postal icon indicating copy to clipboard operation
postal copied to clipboard

The virtual path '/' maps to another application, which is not allowed

Open uchetfield opened this issue 8 years ago • 6 comments

Just starting to use this library I get this exception when trying to send a basic email using Asp.Net MVC 5:

Nothing fancy, Just followed the instructions on the website. I am running my application as http://localhost/sitename. If I change my url to be http://localhost/ the email works without an issue This is the same issue as https://github.com/andrewdavey/postal/issues/65

[ArgumentException: The virtual path '/' maps to another application, which is not allowed.] System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +12796283 System.Web.HttpContext.GetFilePathData() +60 System.Web.HttpContext.GetRuntimeConfig() +38 System.Web.HttpRequest.get_Browser() +191 System.Web.HttpRequestWrapper.get_Browser() +18 System.Web.WebPages.BrowserHelpers.GetOverriddenBrowser(HttpContextBase httpContext, Func2 createBrowser) +360 System.Web.WebPages.DisplayModeProvider.<.ctor>b__2(HttpContextBase context) +11 System.Web.WebPages.<GetAvailableDisplayModesForContext>d__4.MoveNext() +192 System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations) +856 System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache) +206 System.Web.Mvc.<>c__DisplayClass6.<FindView>b__4(IViewEngine e) +43 System.Web.Mvc.ViewEngineCollection.Find(Func2 lookup, Boolean trackSearchedPaths) +174 System.Web.Mvc.ViewEngineCollection.Find(Func2 cacheLocator, Func2 locator) +23 Postal.EmailViewRenderer.Render(Email email, String viewName) +63 Postal.EmailService.Send(Email email) +58 UHearth.Web.Controllers.<>c__DisplayClass16.<SendEmailConfirmation>b__15() in c:\Users\Remco\Documents\Visual Studio 2013\Projects\HearthstoneTracker.com\UHearth.Web\Controllers\AccountController.cs:186

uchetfield avatar Feb 12 '16 21:02 uchetfield

I want to clarify my issue. I am utilizing Hangfire to send emails in the background. I have followed the tutorial located http://docs.hangfire.io/en/latest/tutorials/send-email.html. When I have IISExpress configured to debug the site on http://localhost:7706 everything works correctly. When I have IISExpress configured to debug the site on http://localhost:7706/SubSite I receive the error

The virtual path '/' maps to another application, which is not allowed

I have tracked the error down to the following line in the EmailViewRenderer.cs file

            var result = viewEngines.FindView(controllerContext, viewName, null);

of

        IView CreateView(string viewName, ControllerContext controllerContext)
    {
        var result = viewEngines.FindView(controllerContext, viewName, null);
        if (result.View != null)
            return result.View;

        throw new Exception(
            "Email view not found for " + viewName +
            ". Locations searched:" + Environment.NewLine +
            string.Join(Environment.NewLine, result.SearchedLocations)
        );
    }

uchetfield avatar Feb 14 '16 04:02 uchetfield

I found that the issue was that the controllerContext httpContext was not getting set correctly. In the method

    string UrlRoot()
    {
        var httpContext = HttpContext.Current;
        if (httpContext == null)
        {
            return "http://localhost";
        }

        return httpContext.Request.Url.GetLeftPart(UriPartial.Authority) +
               httpContext.Request.ApplicationPath;
    }

if the httpContext is null which is the case when using hangfire the default value is "http://localhost"

If I changed the default value to be "http://localhost/SubSite" then everything will work without an issue. Is there a configuration that I can set to get this to work without modifying the source code?

uchetfield avatar Feb 14 '16 05:02 uchetfield

I'm having the same issue. Is there any solution that does not involve modifying the source code??

mauricioulloa avatar Feb 19 '16 20:02 mauricioulloa

I was able to resolve my issue, I had previously posted on stackoverflow. Here is the link to my issue and resolution. http://stackoverflow.com/questions/35389505/using-postal-and-hangfire-in-subsite

uchetfield avatar Feb 23 '16 19:02 uchetfield

@uchetfield Thanks!

mauricioulloa avatar Feb 23 '16 20:02 mauricioulloa

@mauricioulloa FYI I updated my answer on stackoverflow with a more elegant solution that also resolved some other issues that appeared once my application was a heavy stress.

uchetfield avatar Apr 08 '16 23:04 uchetfield