我有一个自定义模块,它使用Routes.cs和AdminController.cs文件来定义新的url路由和要采取的操作,但只能在用户登录我已尝试添加[授权]在我AdminController.cs文件[使用AllowAnonymous]属性和我都试过,包括在我的Web.config文件中的以下内容:允许匿名用户访问Orchard中的特定URL CMS
<location path="/speedbump">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
这些方法都不似乎工作。我该如何着手确保该网址可以被所有网站的用户/访问者访问,而不仅仅是那些已经登录的用户?谢谢。
Routes.cs文件:
public class Routes : IRouteProvider
{
public void GetRoutes(ICollection<RouteDescriptor> routes)
{
foreach (var routeDescriptor in GetRoutes())
routes.Add(routeDescriptor);
}
public IEnumerable<RouteDescriptor> GetRoutes()
{
return new[] {
new RouteDescriptor {
Priority = 15,
Route = new Route(
"speedbump",
new RouteValueDictionary {
{"area", "Speedbump"},
{"controller", "Admin"},
{"action", "isValidURL"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "Speedbump"}
},
new MvcRouteHandler())
}
};
}
}
AdminController.cs文件:
[Authorize]
public class AdminController : Controller
{
public ActionResult Index()
{
return View();
}
[AllowAnonymous]
public void isValidURL()
{
string requestedURL = Request.QueryString["url"];
//Create a list of strings to contain all the "valid" URLs
var whiteList = new List<string>();
//Add URLs to the list
whiteList.Add("www.google.com");
foreach (string validURL in whiteList)
{
if (requestedURL == validURL)
{
Response.Write("Speedbump");
//Response.Redirect(requestedURL);
}
}
}
}
如果您希望每个人都可以访问,请使用 –
Partha
2014-09-02 23:03:00
这也行不通,Web.config文件中是否存在它需要的特定位置? – EmeraldArcher 2014-09-03 01:42:51
身份验证标记之前的任何位置。你可以粘贴认证标签部分? – Partha 2014-09-03 02:22:39