Browse Source

Git客户端克隆、推送,使用全新地址,测试通过

v1.4
大石头 9 years ago
parent
commit
67a981572c
  1. 31
      GitCandy.Web/App_Start/RouteConfig.cs

31
GitCandy.Web/App_Start/RouteConfig.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
@ -29,17 +30,17 @@ namespace GitCandy
// constraints: new { owner = new UserUrlConstraint() },
// namespaces: new[] { typeof(AccountController).Namespace }
//);
routes.MapRoute(
name: "UserGitAct",
url: "{owner}/{name}/{action}/{*path}",
defaults: new { controller = "Repository", path = UrlParameter.Optional },
constraints: new { owner = new UserUrlConstraint() },
namespaces: new[] { typeof(AccountController).Namespace }
);
routes.MapRoute(
name: "UserGit",
url: "{owner}/{project}/{*verb}",
defaults: new { controller = "Git", action = "Smart" },
constraints: new { owner = new UserUrlConstraint(), verb = new GitUrlConstraint() },
namespaces: new[] { typeof(AccountController).Namespace }
);
routes.MapRoute(
name: "UserGitAct",
url: "{owner}/{name}/{action}/{*path}",
defaults: new { controller = "Repository", path = UrlParameter.Optional },
constraints: new { owner = new UserUrlConstraint() },
namespaces: new[] { typeof(AccountController).Namespace }
);
@ -150,6 +151,22 @@ namespace GitCandy
}
}
class GitUrlConstraint : IRouteConstraint
{
private static HashSet<String> _cache = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"info/refs","git-upload-pack","git-receive-pack"
};
public bool Match(HttpContextBase httpContext, Route route, String parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
var name = values[parameterName] + "";
if (name.IsNullOrEmpty()) return false;
return _cache.Contains(name);
}
}
//class TeamUrlConstraint : IRouteConstraint
//{
// public bool Match(HttpContextBase httpContext, Route route, String parameterName, RouteValueDictionary values, RouteDirection routeDirection)

Loading…
Cancel
Save