Method 'HttpRequestBase.GetBufferlessInputStream' not found when using owin auth on mono - asp.net

I deployed a Asp.Net Web API project onto my CentOS server running mono 4.3.0 (compiled from mono-4.2.1.36 branch released 2 days ago). I built the project using VS2015 enpty web api template and added owin authentication in an attempt to get a web api working with authentication using bearer tokens.
I'm hosting the project on apache server using mod_mono.
When running the project locally on my windows machine, everything works perfectly. On Linux, when I send a http POST to the /token endpoint, the server returns a 200 OK, but without any response payload (which would include the bearer token the client needs to authenticate subsequent requests). At the same time, the server logs an exception (following).
System.MissingMethodException: Method 'HttpRequestBase.GetBufferlessInputStream' not found.
at Microsoft.Owin.Host.SystemWeb.CallStreams.InputStream.get_Stream () <0xb0e339b8 + 0x00013> in <filename unknown>:0
at Microsoft.Owin.Host.SystemWeb.CallStreams.DelegatingStream.get_CanRead () <0xb0e45eb0 + 0x00013> in <filename unknown>:0
at System.IO.StreamReader..ctor (System.IO.Stream stream, System.Text.Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen) <0xb0e5d790 + 0x0005f> in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (System.IO.Stream,System.Text.Encoding,bool,int,bool)
at Microsoft.Owin.OwinRequest+<ReadFormAsync>d__0.MoveNext () <0xb0e33510 + 0x000f3> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xb0e34a68 + 0x0002b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0xb0e346d0 + 0x000bb> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0xb0e34588 + 0x0007f> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0xb270df98 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () <0xb270e1d0 + 0x00017> in <filename unknown>:0
at Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler+<InvokeTokenEndpointAsync>d__22.MoveNext () <0xb0e2f118 + 0x00463> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xb0e34a68 + 0x0002b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0xb0e346d0 + 0x000bb> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0xb0e34588 + 0x0007f> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0xb270df98 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0xb270df70 + 0x00013> in <filename unknown>:0
at Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler+<InvokeAsync>d__0.MoveNext () <0xb270e790 + 0x007a7> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xb0e34a68 + 0x0002b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0xb0e346d0 + 0x000bb> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0xb0e34588 + 0x0007f> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0xb270df98 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () <0xb270f5b0 + 0x00013> in <filename unknown>:0
at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1+<Invoke>d__0[TOptions].MoveNext () <0xb270b2a0 + 0x0030f> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xb0e34a68 + 0x0002b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0xb0e346d0 + 0x000bb> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0xb0e34588 + 0x0007f> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0xb270df98 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0xb270df70 + 0x00013> in <filename unknown>:0
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage+<RunApp>d__5.MoveNext () <0xb270aa98 + 0x00173> in <filename unknown>:0
After googling I found that this exception has been fixed in another namespace, but note this originates in Microsoft.Owin.Host.SystemWeb.
Is there a workaround to get rid of the exception, and does anyone have information on if that exception is the reason for the behavior I'm facing or is there something else I can try in order to get bearer token based authentication working?
In my AuthorizationServerProvider I implement the following methods:
(also, when running on Linux the response headers do not include Access-Control-Allow-Origin like they do on Windows)
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
context.Validated();
return Task.FromResult<object>(null);
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
//check credentials
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); //etc
var props = new AuthenticationProperties(new Dictionary<string, string>
{
{ "as:client_id", (context.ClientId == null) ? string.Empty : context.ClientId },
{ "userName", context.UserName }
});
var ticket = new AuthenticationTicket(identity, props);
context.Validated(ticket);
}
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
{
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
{
context.AdditionalResponseParameters.Add(property.Key, property.Value);
}
return Task.FromResult<object>(null);
}
My Startup.cs looks like this:
public void Configuration(IAppBuilder app)
{
ConfigureOAuth(app);
HttpConfiguration config = new HttpConfiguration();
config.Filters.Add(new AuthorizeAttribute());
WebApiConfig.Register(config);
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
GlobalConfiguration.Configuration.Filters.Add(new AuthorizeAttribute());
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
}
public void ConfigureOAuth(IAppBuilder app)
{
OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(15),
Provider = new BoaAuthorizationServerProvider(),
RefreshTokenProvider = new BoaRefreshTokenProvider(),
ApplicationCanDisplayErrors = true,
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthServerOptions);
}
EDIT:
Some more information on this:
I tried the old remove-the-problematic-dll -trick, and I no longer get that exception, but however I do get a 500 Internal Server Error, when sending a http POST to the token endpoint (the same that works on windows).
This is the exception:
System.Web.HttpException
Method 'POST' is not allowed when accessing file '/webapitest/token'
Description: HTTP 500.Error processing request.
Details: Error processing request.
Exception stack trace:
at System.Web.DefaultHttpHandler.BeginProcessRequest (System.Web.HttpContext context, System.AsyncCallback callback, System.Object state) in <filename unknown>:line 0
at System.Web.HttpApplication+<Pipeline>c__Iterator1.MoveNext () in <filename unknown>:line 0
at System.Web.HttpApplication.Tick () in <filename unknown>:line 0
Note the Startup configuration above, is there anything there that mono does not support? If not, this seems like either a configuration problem or a bug in mono as someone previously commented that they get the same MissingMethodException about GetBufferlessInputStream that happens on Ubuntu. That comment has then been removed.

This error is still reproduced on mono builds downloaded from official repos(seems like correct GetBufferlessInputStream & GetBufferedInputStream were implemented in that commit:
303d876370017774445c71736cf34e851e5cb037).
The easiest way for me was to update dependent libraries from nightlybuild repo(not need to compile whole project and to update only required libraries for disk space saving).
Update instructions for Debian:
echo "deb http://download.mono-project.com/repo/debian nightly main" | sudo tee /etc/apt/sources.list.d/mono-nightly.list
sudo apt-get update
sudo apt-get install libmono-system-net-http-webrequest4.0-cil
(any other libmono http library should work too, list of needed packages will be composed automatically)

Related

How to upgrade to 3.2.1.0 in Mono

Npgsql 3.1.9 is used in ASP.NET MVC4 application in Mono 4.4.1
Visual Studio Community Edition 2015 is used for develpment.
Ngpsql was upgraded to 3.2.1.0 from Nuget package manager.
It installed a lot of new .NET framework assemblies.
Application was re-compiled in Visual Studio and copied to Debian Linux into Mono.
Trying to run application in Mono now causes exception
Could not load type 'System.Net.HttpStatusDescription' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
with stack trace below.
How to run this application in Mono using latest npgsql?
In windows from Visual Studio it runs OK.
Could not load type 'System.Net.HttpStatusDescription' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
System.TypeLoadException: Could not load type 'System.Net.HttpStatusDescription' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at System.Web.Http.WebHost.HttpControllerHandler+<CopyResponseStatusAndHeadersAsync>d__31.MoveNext () <0x40bbf6b0 + 0x000eb> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x40bc12f0 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x40bc0e60 + 0x0010b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x40bc0cb0 + 0x000b3> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x413bc1b0 + 0x00042> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () <0x414e3410 + 0x0001a> in <filename unknown>:0
at System.Web.Http.WebHost.HttpControllerHandler+<CopyResponseAsync>d__7.MoveNext () <0x40bbebc0 + 0x002b5> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x40bc12f0 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x40bc0e60 + 0x0010b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x40bc0cb0 + 0x000b3> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x413bc1b0 + 0x00042> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x414bdce0 + 0x0001a> in <filename unknown>:0
at System.Web.Http.WebHost.HttpControllerHandler+<ProcessRequestAsyncCore>d__0.MoveNext () <0x40b80500 + 0x006e9> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x40bc12f0 + 0x00033> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x40bc0e60 + 0x0010b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x40bc0cb0 + 0x000b3> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x413bc1b0 + 0x00042> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x414bdce0 + 0x0001a> in <filename unknown>:0
at System.Web.TaskAsyncResult.Wait (IAsyncResult result) <0x40bc1ce0 + 0x000c9> in <filename unknown>:0
at System.Web.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.EndProcessRequest (IAsyncResult result) <0x40bc1cb0 + 0x00013> in <filename unknown>:0
at System.Web.HttpApplication.async_handler_complete_cb (IAsyncResult ar) <0x4158bc70 + 0x000ee> in <filename unknown>:0
Update
I uninstalled Netstandard.library package with dependencies using forced uninstall in nuget.
Added System.Net.Http.dll assemby to refences from .NET 4.6 framework assemblies with Copy Local true.
Removed and installed again Microsoft.AspNet.WebApi.Core package
Now running in mono causes error
System.InvalidProgramException
Invalid IL code in System.Net.Http.Headers.MediaTypeHeaderValue:.ctor (string): method body is empty.
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Net.Http.Formatting.
Exception stack trace:
at System.Net.Http.Formatting.MediaTypeConstants..cctor () <0x41e7fb00 + 0x00033> in <filename unknown>:0
Version Information: 4.4.1 (Nightly 4.4.1.0/4747417 K juuli 20 01:02:20 EEST 2016); ASP.NET Version: 4.0.30319.42000
I tried also to install System.Net.Http.dll nuget package but in this case exception described in start of this question occurs in Mono.

System.Web.HttpException with "Type Service not found." in Mono ASP.NET Web Service

I am using mono v4.2.1 and apache2 in ubuntu 14.04
I managed to install my ASP.NET web service in the url: http://myurl/WebService/Service.asmx
But when I open it, I receive this error:
System.Web.HttpException
Type Service not found.
Description: HTTP 500.Error processing request.
Details: Error processing request.
Exception stack trace:
at System.Web.UI.SimpleWebHandlerParser.GetTypeFromBin (System.String tname) <0x40f053e0 + 0x00894> in <filename unknown>:0
at System.Web.Compilation.SimpleBuildProvider.LoadTypeFromBin (System.Web.Compilation.BaseCompiler compiler, System.Web.UI.SimpleWebHandlerParser parser) <0x40f053a0 + 0x00026> in <filename unknown>:0
at System.Web.Compilation.GenericBuildProvider`1[TParser].GetGeneratedType (System.CodeDom.Compiler.CompilerResults results) <0x40f05150 + 0x00085> in <filename unknown>:0
at System.Web.Compilation.BuildManagerCacheItem..ctor (System.Reflection.Assembly assembly, System.Web.Compilation.BuildProvider bp, System.CodeDom.Compiler.CompilerResults results) <0x40f04fc0 + 0x00101> in <filename unknown>:0
at System.Web.Compilation.BuildManager.StoreInCache (System.Web.Compilation.BuildProvider bp, System.Reflection.Assembly compiledAssembly, System.CodeDom.Compiler.CompilerResults results) <0x40f04a60 + 0x0009f> in <filename unknown>:0
at System.Web.Compilation.BuildManager.GenerateAssembly (System.Web.Compilation.AssemblyBuilder abuilder, System.Web.Compilation.BuildProviderGroup group, System.Web.VirtualPath vp, Boolean debug) <0x40f00ff0 + 0x00b94> in <filename unknown>:0
at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) <0x40ee7490 + 0x00579> in <filename unknown>:0
at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) <0x40ee6df0 + 0x00149> in <filename unknown>:0
at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) <0x40ee6a30 + 0x000b7> in <filename unknown>:0
at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) <0x40ee65c0 + 0x00024> in <filename unknown>:0
at System.Web.UI.WebServiceParser.GetCompiledType (System.String inputFile, System.Web.HttpContext context) <0x40ee65a0 + 0x00014> in <filename unknown>:0
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetCompiledType (System.String url, System.Web.HttpContext context) <0x40ee6570 + 0x00022> in <filename unknown>:0
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler (System.Web.HttpContext context, System.String verb, System.String url, System.String filePath) <0x40edf510 + 0x0014a> in <filename unknown>:0
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler (System.Web.HttpContext context, System.String requestType, System.String url, System.String pathTranslated) <0x40edf050 + 0x00241> in <filename unknown>:0
at System.Web.HttpApplication.GetHandler (System.Web.HttpContext context, System.String url, Boolean ignoreContextHandler) <0x40ed71f0 + 0x002f3> in <filename unknown>:0
at System.Web.HttpApplication.GetHandler (System.Web.HttpContext context, System.String url) <0x40ed71b0 + 0x00020> in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator1.MoveNext () <0x40ebcf60 + 0x02b62> in <filename unknown>:0
This is my Service.asmx:
<%# WebService Language="C#" Class="Service" %>
And the Service class is in a library which is added by reference:
using System.Web.Services;
[WebService(Namespace = "http://myurl/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : WebService
{
public Service()
{
}
}
The point is it works completely OK in Microsoft Visual Studio but mono has a problem and I don't know where to look or what to do.
I figured out that it was because the root directory was not correctly set.
I used xsp4 instead of apache2 and it fixed.

Issue after updating to mono 4.0.1 on Ubuntu

I just upgraded to the just released Mono version 4.0.1 on my ubuntu machines. The previous installed version of mono was 3.2.7 (if I remember correctly).
Now the issue:
My first issue is regarding SignalR and self-hosting. I have a .NET 4.5.1 console application in which I self host NancyFx, Web Api and SignalR using OWIN. When running on mono 3.2.7 there was no issues to my knowledge but when I try to start the application on mono 4.0.1 I get the following stack trace:
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in (wrapper delegate-invoke) <Module>:invoke_callvirt_CancellationTokenRegistration_CancellationToken&_Action`1<object>_object (System.Threading.CancellationToken&,System.Action`1<object>,object): IL_0057: castclass 0x00000007
at Microsoft.AspNet.SignalR.Infrastructure.CancellationTokenExtensions.SafeRegister (CancellationToken cancellationToken, System.Action`1 callback, System.Object state) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.SignalR.Hosting.HostDependencyResolverExtensions.InitializeResolverDispose (IDependencyResolver resolver, CancellationToken hostShutdownToken) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.SignalR.Hosting.HostDependencyResolverExtensions.InitializeHost (IDependencyResolver resolver, System.String instanceName, CancellationToken hostShutdownToken) [0x00000] in <filename unknown>:0
at Owin.OwinExtensions.UseSignalRMiddleware[HubDispatcherMiddleware] (IAppBuilder builder, System.Object[] args) [0x00000] in <filename unknown>:0
at Owin.OwinExtensions.RunSignalR (IAppBuilder builder, Microsoft.AspNet.SignalR.HubConfiguration configuration) [0x00000] in <filename unknown>:0
at Owin.OwinExtensions+<>c__DisplayClass1.<MapSignalR>b__0 (IAppBuilder subApp) [0x00000] in <filename unknown>:0
at Owin.MapExtensions.Map (IAppBuilder app, PathString pathMatch, System.Action`1 configuration) [0x00000] in <filename unknown>:0
at Owin.MapExtensions.Map (IAppBuilder app, System.String pathMatch, System.Action`1 configuration) [0x00000] in <filename unknown>:0
at Owin.OwinExtensions.MapSignalR (IAppBuilder builder, System.String path, Microsoft.AspNet.SignalR.HubConfiguration configuration) [0x00000] in <filename unknown>:0
at Owin.OwinExtensions.MapSignalR (IAppBuilder builder, Microsoft.AspNet.SignalR.HubConfiguration configuration) [0x00000] in <filename unknown>:0
at Owin.OwinExtensions.MapSignalR (IAppBuilder builder) [0x00000] in <filename unknown>:0
I have no clue to what this error could mean and I'm greatful for all assistance. I'm using Microsoft ASP.NET SignalR Self Host package version 2.2.0.
And as a side note, I've compiled all my assemblies on the new mono version.
Kind regards,
Simon
This turned out to be a Mono issue which was recently fixed: https://bugzilla.xamarin.com/show_bug.cgi?id=29665

How to serve favicon.ico and robots.txt files from ASP.NET MVC3 application

ASP.NET MVC3 application is hosted in Apache in Mono as virtual host with address http://www.mysite.com
Requests for files robots.txt , favicon.ico and apple-touch-icon.png cause 404 error below since
there are no MVC3 controllers for those names.
How to server those files ? It it possible to force Apache to serve them as regular files or can we force MVC3 application to return those files ?
Which is proper way to implement this ?
System.Web.HttpException: The controller for path '/robots.txt' was not found or does not implement IController.
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance (System.Web.Routing.RequestContext requestContext, System.Type controllerType) [0x00000] in <filename unknown>:0
at System.Web.Mvc.DefaultControllerFactory.CreateController (System.Web.Routing.RequestContext requestContext, System.String controllerName) [0x00000] in <filename unknown>:0
at System.Web.Mvc.MvcHandler.ProcessRequestInit (System.Web.HttpContextBase httpContext, IController& controller, IControllerFactory& factory) [0x00000] in <filename unknown>:0
at System.Web.Mvc.MvcHandler+<>c__DisplayClass6.<BeginProcessRequest>b__2 () [0x00000] in <filename unknown>:0
at System.Web.Mvc.SecurityUtil+<>c__DisplayClassb`1[System.IAsyncResult].<ProcessInApplicationTrust>b__a () [0x00000] in <filename unknown>:0
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0 (System.Action f) [0x00000] in <filename unknown>:0
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust (System.Action action) [0x00000] in <filename unknown>:0
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[IAsyncResult] (System.Func`1 func) [0x00000] in <filename unknown>:0
at System.Web.Mvc.MvcHandler.BeginProcessRequest (System.Web.HttpContextBase httpContext, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0
at System.Web.Mvc.MvcHandler.BeginProcessRequest (System.Web.HttpContext httpContext, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest (System.Web.HttpContext context, System.AsyncCallback cb, System.Object extraData) [0x00000] in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator3.MoveNext () [0x00000] in <filename unknown>:0
at System.Web.HttpApplication.Tick () [0x00000] in <filename unknown>:0
Fixing robots.txt:
Right click the project name and select "Add->New Item"
Choose "Text File" and call it "robots.txt"
You can leave this file blank
Fixing favicon.ico:
Go to the RegisterRoutes method of the Global.asax.cs file and add this near the top: You can look at this page for more info: Favicon Icon-MVC3 ASP.NET
routes.IgnoreRoute("{*favicon}", new { favicon = #"(.*/)?favicon.ico(/.*)?" });
Fixing apple-touch-icon.png:
Look at these websites
Why am I getting error for apple-touch-icon-precomposed.png
http://mathiasbynens.be/notes/touch-icons

asp.net on mono Failed to map path '/'

I installed mono from source on a Centos 6.4 to test a msc asp web site.
It seems to work fine all but
some pages return this error
System.InvalidOperationException
Failed to map path '/'
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object):
System.Web.
at System.Web.HttpRequest.MapPath (System.String virtualPath, System.String baseVirtualDir, Boolean allowCrossAppMapping) [0x00000] in <filename unknown>:0
at System.Web.HttpRequest.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0
at System.Web.Hosting.HostingEnvironment.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0
at System.Web.Hosting.DefaultVirtualPathProvider.DirectoryExists (System.String virtualDir) [0x00000] in <filename unknown>:0
at System.Web.Configuration.WebConfigurationManager.FindWebConfig (System.String path, System.Boolean& inAnotherApp) [0x00000] in <filename unknown>:0
at System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration (System.String path, System.String site, System.String locationSubPath, System.String server, System.String userName, System.String password, Boolean fweb) [0x00000] in <filename unknown>:0
at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path, System.Web.HttpContext context) [0x00000] in <filename unknown>:0
at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path) [0x00000] in <filename unknown>:0
at System.Web.Security.SqliteMembershipProvider.Initialize (System.String name, System.Collections.Specialized.NameValueCollection config) [0x00000] in <filename unknown>:0
at System.Web.Configuration.ProvidersHelper.InstantiateProvider (System.Configuration.ProviderSettings providerSettings, System.Type providerType) [0x00000] in <filename unknown>:0
at System.Web.Configuration.ProvidersHelper.InstantiateProviders (System.Configuration.ProviderSettingsCollection configProviders, System.Configuration.Provider.ProviderCollection providers, System.Type providerType) [0x00000] in <filename unknown>:0
at System.Web.Security.Membership..cctor () [0x00000] in <filename unknown>:0
I did the same thing on a debian and It works fine.
Do you have any suggestions?
Find all your Server.MapPaths and change from
Server.MapPaths(#"\")
to
Server.MapPaths(Path.DirectorySeparatorChar)
Have you checked the paths in your view files? Just as a reminder:
'/' like in <script src="/myScript.js"></script> maps to the DocumentRoot folder defined on your /sites-available/.conf, it may be something like /var/www
'~/' like in <script src="#Url.Content("~/scripts/script1.js")"></script> maps to the path where your mvc application is, it may be somethin like /var/www/site1
'../' would try to access one folder above the DocumentRoot folder. This may actually be forbbiden by your apache site configuration (recommended).
Also note that if your run your mvc app from monodevelop/xspServer the document root and the mvc application path are actually the same but if you install your mvc app on apache they may not be the same path.
This error occurs because there is a bug in mono System.Web
It contain this check (https://github.com/mono/mono/blob/mono-3.2.1-branch/mcs/class/System.Web/System.Web/HttpRequest.cs#L1565)
if (!isAppVirtualPath && !virtualPath.StartsWith (appVirtualPath, RuntimeHelpers.StringComparison))
throw new InvalidOperationException (String.Format ("Failed to map path '{0}'", virtualPath));
To fix this, you can comment those lines in Mono surce code and re-compile Mono.
This bug is in latest Mono also.
Links:
https://bugzilla.xamarin.com/show_bug.cgi?id=24457
I had the same error, with exactly the same stacktrace.
It only occured on the first request when apache was just started. The error did not occur after the first request.
I solved this by removing WebMatrix.WebData.dll
This will probably have some consequences when you use SimpleMembershipProvider and it might affect OpenAuth functionality on MVC4.

Resources