微信请求的控制get、post方法,是不是一定要加视图?还是可以不加?
为什么服务器上出现找不到视图的警告? public class WeixinController : Controller
{
public WeixinController()
{ } /// <summary>
/// 微信后台验证地址(使用Get),微信后台的“接口配置信息”的Url
/// </summary>
[HttpGet]
[ActionName("Index")]
public ActionResult Get(string signature, string timestamp, string nonce, string echostr)
{
var token = "LingZhuo20150716";//微信公众平台后台设置的Token
if (string.IsNullOrEmpty(token)) return Content("请先设置Token!");
var ent = "";
if (!BasicAPI.CheckSignature(signature, timestamp, nonce, token, out ent))
{
return Content("参数错误!");
}
return Content(echostr); //返回随机字符串则表示验证通过
}
/// <summary>
/// 用户发送消息后,微信平台自动Post一个请求到这里,并等待响应XML。
/// </summary>
[HttpPost]
[ActionName("Index")]
public ActionResult Post(string signature, string timestamp, string nonce, string echostr)
{
WeixinMessage message = null;
using (var streamReader = new StreamReader(Request.InputStream))
{
message = AcceptMessageAPI.Parse(streamReader.ReadToEnd());
}
var response = new WeixinExecutor().Execute(message);
return new ContentResult
{
Content = response,
ContentType = "text/xml",
ContentEncoding = System.Text.UTF8Encoding.UTF8
};
}
路由到底要怎么设置? public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
为什么服务器上出现找不到视图的警告? public class WeixinController : Controller
{
public WeixinController()
{ } /// <summary>
/// 微信后台验证地址(使用Get),微信后台的“接口配置信息”的Url
/// </summary>
[HttpGet]
[ActionName("Index")]
public ActionResult Get(string signature, string timestamp, string nonce, string echostr)
{
var token = "LingZhuo20150716";//微信公众平台后台设置的Token
if (string.IsNullOrEmpty(token)) return Content("请先设置Token!");
var ent = "";
if (!BasicAPI.CheckSignature(signature, timestamp, nonce, token, out ent))
{
return Content("参数错误!");
}
return Content(echostr); //返回随机字符串则表示验证通过
}
/// <summary>
/// 用户发送消息后,微信平台自动Post一个请求到这里,并等待响应XML。
/// </summary>
[HttpPost]
[ActionName("Index")]
public ActionResult Post(string signature, string timestamp, string nonce, string echostr)
{
WeixinMessage message = null;
using (var streamReader = new StreamReader(Request.InputStream))
{
message = AcceptMessageAPI.Parse(streamReader.ReadToEnd());
}
var response = new WeixinExecutor().Execute(message);
return new ContentResult
{
Content = response,
ContentType = "text/xml",
ContentEncoding = System.Text.UTF8Encoding.UTF8
};
}
路由到底要怎么设置? public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
解决方案 »
- nhibernate 在 web.config 中如何配置
- Graphics如何压缩图像质量
- GridView1 日期字段问题?
- 如何在aspx网页中使用iframe?
- 没分了,一个页面,包含一个iframe,如何刷新页面时不刷新iframe内的页面?
- ASP.Net怎么对应windowsXP sp2啊??
- 有关VisualStudio 2005的问题(100分大谢)
- 该项不适于在指定状态下使用
- 下载Excle文件 解锁
- cshtml 文件在项目中复制改名,相当于新建一个页面吗?
- ASP.net与easyui的dialog实现弹窗的ajax,要么不实现异步,要么一开始就显示div
- 用户 'sa' 登录失败。求大神解决啊
http://www.cnblogs.com/deepleo/p/weixinSDK.html
这个地址不对吧?
看你的控制器,应该是
http://www.lingzhuogz.com/weixin/Index?signature=7b8ce4cd8a455a6e70ff31a295aa2452179746e6×tamp=1405838972&nonce=1482481641ps,多参数可以放在form里,这种地址太丑了
为什么服务器上出现找不到视图的警告?】可以不要加视图,警告的原因应该是针对http://www.lingzhuogz.com/weixin/weixin, WeixinController中有没有weixin名称的action?