写条url重写规则即可
大神怎么写,我是新手不是很懂,能给个例子或者撒的吗
取决于用什么基础模块了;
mvc 或者 wcf 都可以在函数上面直接通过XXAttribute设置,也可以由其他层次的拦截器(如filter、httpmodule等等,而且通常需要分解url来完成)一次性自定义map到类或者函数等处理;
如果是从tcp 或者 http做起拦不拦截都自己说了算,tcp做起你甚至可以不必完全遵从http规则都可以。
有点懵,我是学前端的大神,看不大懂
@FL陌上花开:
[Route(WebApiConfig.BaseUrl + "/Customer/WebSite/{webSite}")]
public IHttpActionResult GetCustomerByDns(string webSite)
说多了是泪,你别选了,这个例子直接简单粗暴 ——
@花飘水流兮: 选什么,你这例子没发完吗,
@FL陌上花开:
拿去看~~看不懂就爱莫能助了。
[LApiAuthenticate]
public class CustomersController : ApiController
{
[ResponseType(typeof(DbCutstomer))]
[Route(WebApiConfig.BaseUrl + "/Customer/WebSite/{webSite}")]
public IHttpActionResult GetCustomerByDns(string webSite)
{
var publicKeyBase64 = ActionContext.Request.Headers.GetValues("publicKey").FirstOrDefault();
if (string.IsNullOrEmpty(publicKeyBase64))
{
return StatusCode(HttpStatusCode.Conflict);
}
var publickKey = Encoding.UTF8.GetString(Convert.FromBase64String(publicKeyBase64));
var webSiteString = Encoding.UTF8.GetString(Convert.FromBase64String(webSite));
var customer = _db.Customers.FirstOrDefault(t => t.WebSite == webSiteString);
if (customer == null) return NotFound();
var serverInfo = _db.Servers.Find(customer.ServerID);
if (serverInfo == null)return NotFound();
var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(publickKey);
var connectionString = $"Data Source={serverInfo.HostName},{serverInfo.DbPort};Initial Catalog=g{customer.ID};User ID={serverInfo.DbUser};Password={serverInfo.DbPwd}";
var connectionBuffer = Encoding.UTF8.GetBytes(connectionString);
var dbCustomer = new DbCutstomer();
customer.CopyTo(dbCustomer);
dbCustomer.DbConnectionInfo = Convert.ToBase64String(rsa.Encrypt(connectionBuffer, false));
return Ok(dbCustomer);
}
函数完....
....
@花飘水流兮 嗯,非常感谢