答案 0 :(得分:3)
完全符合名称
[System.Web.Mvc.AllowAnonymous]
public ActionResult SomeAction()
{ ...
答案 1 :(得分:1)
在页面顶部,使用namespace
,如:
using System.Web.Mvc;
答案 2 :(得分:1)
只需使用以下内容删除它:
startServer("http://", "localhost", "Sample", "UI", "9090");
public static void startServer(String protocol, String host, String webapp, String ui, String port) {
try {
String BASE_URI = protocol + host + ":" + port + "/" + webapp + "/";
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI));
/*--- Static UI Content ---*/
if(ui!=null && !ui.equals("")) {
String jarPath = getJarPath(SampleGrizzlyWebServer.class);
if (jarPath != null) {
CLStaticHttpHandler clStaticHttpHandler = new CLStaticHttpHandler(
new URLClassLoader(new URL[]{new File(jarPath).toURI().toURL()}),
"/", "/lib/", "/js/", "/css/");
ServerConfiguration sc = httpServer.getServerConfiguration();
sc.addHttpHandler(clStaticHttpHandler, HttpHandlerRegistration.builder().contextPath("/" + webapp + "/" + ui + "").urlPattern("").build());
}
}
/*--- SampleAdmin WebappContext ---*/
WebappContext SampleAdminContext = new WebappContext("WebappContext", "/" + webapp + "/" + "SampleAdmin");
/*--- Servlet ---*/
final ResourceConfig sampleAdminRc = new SampleAdminApplication();
ServletRegistration sampleAdminRegistration = SampleAdminContext.addServlet("ServletContainer", new ServletContainer(sampleAdminRc));
sampleAdminRegistration.addMapping("/*");
/**
* Deploy Server
*/
SampleAdminContext.deploy(httpServer);
httpServer.start();
System.out.println("Jersey app started with WADL available at:");
System.out.println(BASE_URI + "SampleAdmin/application.wdl");
System.out.println("Hit enter to stop it...");
System.in.read();
httpServer.shutdown();
}
catch(Exception ex) {
System.err.println("Error: " + ex.getMessage());
}
}
因为该命名空间用于WebAPI,而using System.Web.Http;
用于MVC控制器。例如,在同一文件中使用这两个名称空间可能会导致System.Web.Mvc
和Authorize
混淆。