Regarding to this thread: 404 Not found
I still have this issue on Win 8.1 - VS 2013-1
<!--<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>-->
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
and
public class HelloAppHost : AppHostBase
{
/// <summary>
/// Initializes a new instance of your ServiceStack application, with the specified name and assembly containing the services.
/// </summary>
public HelloAppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }
/// <summary>
/// Configure the container with the necessary routes for your ServiceStack application.
/// </summary>
/// <param name="container">The built-in IoC used with ServiceStack.</param>
public override void Configure(Container container)
{
//Register user-defined REST-ful urls. You can access the service at the url similar to the following.
//http://localhost/ServiceStack.Hello/servicestack/hello or http://localhost/ServiceStack.Hello/servicestack/hello/John%20Doe
//You can change /servicestack/ to a custom path in the web.config.
SetConfig(new HostConfig
{
HandlerFactoryPath = "api"
});
SetConfig(new HostConfig { DebugMode = true });
Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name}");
}
}
When I uncomment the second system.webServer tag, I only get HandlerNotFound Exceptions from the api route. When I remove the location tag in web.config the same errors occur.
Like it is now it works ...
Any help for clarification appreciated,
thanks Norbert
You need to change the following:
SetConfig(new HostConfig
{
HandlerFactoryPath = "api"
});
SetConfig(new HostConfig { DebugMode = true });
to
SetConfig(new HostConfig
{
HandlerFactoryPath = "/api",
DebugMode = true
};
Just a guess, but your second instance of HostConfig is probably overriding the first one.
Related
I've tried resolving this from answers in other and similar posts, but no luck.
I'm Using MVC 5, framework 4.8 latest VS2017.
Thanks
My Config is: (including other attempts)
<configuration>
<appSettings>
<!--<add key="owin:AutomaticAppStartup" value="false" />-->
<add key="owin:HandleAllRequests" value="true"/>
<!--<add key="owin:AppStartup" value="Api.xxx" />-->
</appSettings>
</configuration>
Startup class is:
[assembly: OwinStartupAttribute(typeof(Api.xxx.Startup))]
namespace Api.xxx
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Allow all origins
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
….
}
}
}
and Api is:
namespace Api.xxx
{
[Route("values")]
public class ValuesController : ApiController
{
private static readonly Random _random = new Random();
public IEnumerable<string> Get()
{
var random = new Random();
return new[]
{
_random.Next(0, 10).ToString(),
_random.Next(0, 10).ToString()
};
}
}
}
I think you need to change
[assembly: OwinStartupAttribute(typeof(Api.xxx.Startup))]
to
[assembly: OwinStartup(typeof(Api.xxx.Startup))]
Reference: https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection
I've been struggling for 4 hours and I still didn't get any solution. I already apply some modification but still my post and delete api returns the error 500.
GET js
$.getJSON(API_URL + 'api/claim/search', params).done(function (data) {
myJsonObject = data;
d.resolve(data);
});
return d.promise();
API
[Route("api/claim/search")]
[System.Web.Http.AcceptVerbs("GET")]
[System.Web.Http.HttpGet]
public IEnumerable<ClaimInfo> Get([FromUri] ClaimSearch obj_ClaimSearch)
{
//my code
}
This get method is working 100%
POST js
$.ajax({
type: "POST",
data: JSON.stringify(p[0]),
url: API_URL + "api/claim/" + (editorPage === "resubmission" ? "saveresubmissionpatient": "savepatient"),
contentType: "application/json",
success: function (data) {
},
error: function () {
}
});
API
[Route("api/claim/savepatient")]
[System.Web.Http.AcceptVerbs("POST")]
[System.Web.Http.HttpPost]
public Guid SavePatient([FromBody]ClaimInfo claimInfo)
{
//my code
}
And here is my WebApi.Config.cs
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
I already apply this webserver thing in my config
<modules>
<remove name="WebDAVModule" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v16.2, Version=16.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
I had a similar issue, and it had to do with the name of the function catching the request. For some reason, GET functions did this automatically but POST did not always do so. You could try explicitly naming it like this, and see if it also solves your problem:
[Route("api/claim/savepatient")]
[System.Web.Http.AcceptVerbs("POST")]
[System.Web.Http.HttpPost, ActionName("SavePatient")]
public Guid SavePatient([FromBody]ClaimInfo claimInfo)
{
//my code
}
Note that I changed [System.Web.Http.HttpPost] to [System.Web.Http.HttpPost, ActionName("SavePatient")]
You have named the action "savepatient" instead of Post. The router matches /api/{controller} to your {controller}Controller Class. The HTTP method must match the public method of the class. Try renaming "SavePatient" to "Post" (or "Put" if you use that method).
public class ClaimController : ApiBaseController
{
//[Route("api/claim/")] don't need this
public Guid Post([FromBody]ClaimInfo claimInfo)
{
//my code to add new claiminfo
}
//[Route("api/claim/")] don't need this
public Guid Put([FromBody]ClaimInfo claimInfo)
{
//my code to edit claiminfo
}
And remove the extra path on the url:
url: API_URL + "api/claim/"
So i had this working, ive switched to paket and i guess some versions of dll's have changed.
However I still do not understand the error i am getting.
System.ArgumentException : LoggerName already in use
Parameter name: loggerName
my code is basically exactly as it is on here
http://www.tomdupont.net/2015/06/capture-xunit-test-output-with-nlog-and.html
public class NLogTests : IDisposable
{
private readonly ILogger _logger;
public NLogTests(ITestOutputHelper outputHelper)
{
_logger = outputHelper.GetNLogLogger();
}
public void Dispose()
{
_logger.RemoveTestOutputHelper();
}
[Fact]
public void Hello()
{
_logger.Trace("World Trace");
_logger.Debug("World Debug");
_logger.Warn("World Warn");
_logger.Error("World Error");
}
}
and config
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<extensions>
<add assembly="xunit.NLog" />
</extensions>
<targets async="false">
<target xsi:type="TestOutput"
layout="${time}|${level:uppercase=true}|${logger}|${message}"
name="Test" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="Test" />
</rules>
</nlog>
The GetNLogLogger method has an overload that takes a logger name and a bool for incremental suffixes. Using these does not help.
I am really confused.
stacktrace:
System.ArgumentException
LoggerName already in use
Parameter name: loggerName
at Xunit.NLog.Targets.TestOutputTarget.Add(ITestOutputHelper testOutputHelper, String loggerName)
at Xunit.NLog.Helpers.TestOutputHelpers.AddTestOutputHelper(ITestOutputHelper testOutputHelper, String loggerName, Boolean addNumericSuffix)
at Xunit.NLogTestOutputExtensions.GetNLogLogger(ITestOutputHelper testOutputHelper, String loggerName, Boolean addNumericSuffix)
at ProjectRake.BusinessLogic.Spec.TautologiesToVerifyNLogOutput..ctor(ITestOutputHelper outputHelper) in M:\programming\ProjectRake\src\server\ProjectRake.BusinessLogic.Spec\TautologiesToVerifyNLogOutput.cs:line 19
edit:
have downgraded all xunit stuff to 2.1.0, same issue.
outputHelper.GetNLogLogger(); is calling AddTestOutputHelper("")
I guess it only works if you call it once.
You can use outputHelper.GetNLogLogger("myname"); or outputHelper.GetNLogLogger(typeof(NLogTests).Name);
I have a base class that I'm trying to use in a View. I understand now that #model is really an implementation of 'WebViewPage'. So, I believe there is probably a better way to accomplish what I want, maybe with an Action Filter or my BaseController object.
I was trying to do something like this:
public abstract class AuthenticatedViewPageBase : WebViewPage
{
private Login _user;
protected override void InitializePage()
{
_user = Session["User"] as Login;
}
public bool HasPermission(Permissions permission)
{
return HasPermission(new List<Permissions> { permission });
}
public bool HasPermission(List<Permissions> permissions)
{
if (_user == null)
_user = Session["User"] as Login;
return _user != null && permissions.Any(thisPerm => _user.Permissions.Any(p => p.PermissionId == (int)thisPerm));
}
}
And use it in a List View like this:
#using PublicationSystem.Model.Enums
#inherits PublicationSystem.Helpers.AuthenticatedViewPageBase
#model IEnumerable<PublicationSystem.Model.Profile>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_LayoutSmBanner.cshtml";
}
#if (HasPermission(new List<Permissions>
{
Permissions.userCreate
}))
{
<p>
#Html.ActionLink("Create New", "Create");
</p>
}
....
But of course, I cannot use #inherits and #model together. (The Profile class is a simple model.)
What would be a good way to get abilities of function like HasPermission in MVC?
I defined two similar classes:
public abstract class AuthenticatedViewPageBase : WebViewPage
{
//....
}
public abstract class AuthenticatedViewPageBase<TModel> : WebViewPage<TModel>
{
//....
}
Then set \Views\web.config like this:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="PublicationSystem.Helpers.AuthenticatedViewPageBase">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Optimization" />
<add namespace="PublicationSystem" />
</namespaces>
</pages>
</system.web.webPages.razor>
Now my pages can use #model as normally and get the custom methods from my abstract version of WebViewPage.
#model IEnumerable<PublicationSystem.Model.Profile>
I am using MVC 5 with OWIN Authentication.
Here are the code for my StartUp.cs.
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = new TimeSpan(60000000000)
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
The expiration time is set to 60000000000 nano seconds.
Now the requirement is when the cookie is expired, I need to redirect to Login screen.
How to do that?
Hope this will help someone to debug...
The error is in web.config file
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
<system.webServer>
here the name Forms authenticationModule is a typo. it should be
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
<system.webServer>
And voilla it started working.
I found this example is more better:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(15),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
},
SlidingExpiration = false,
ExpireTimeSpan = TimeSpan.FromMinutes(30)
});
Paste code above in Startup.Auth.cs file from App_Start folder.