62,041
社区成员
发帖
与我相关
我的任务
分享
<img src="/Analysis/SingleAnalysis/GetResultByYear?ID=3&year=2012&guid=DEBF000F-4C18-64E7-9B05-796B3300D2C7"/>
[NeedSignIn]
public ActionResult GetResultByYear(int ID= 0, int year = 0)
{
string XTitle = "时间(单位:月份)";
string YTitle = ControllerHelp.GetYTitle(int.Parse(nodeType));
var values = busiSvc.GetResultByYear(ID, year);
return File(MvcChart.DrawSeries(values, "", XTitle, YTitle, SeriesChartType.Column, true), "image/*");
}
<img src="/Analysis/SingleAnalysis/GetResultByYear?ID=3&year=2012&guid=DEBF000F-4C18-64E7-9B05-796B3300D2C7"/>
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile(imgUrl, filePath);
public class MyWebClient : WebClient
{
private readonly CookieContainer m_container = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
HttpWebRequest webRequest = request as HttpWebRequest;
if (webRequest != null)
{
webRequest.CookieContainer = m_container;
}
return request;
}
}
然后调用的时候:
var client = new MyWebClient();
wc.UploadValues("登录地址", new NameValueCollection {{"用户名", "xxxx"}, {"密码", "xxxx"}});
client.DownloadFile(imgUrl, filePath);
不过这样总觉得怪怪的,感觉hack自己的系统。。。
string url= Request.UrlReferrer.ToString();
if(url=="你前台要浏览的那个url")
return true;
这样就能保证只有前台指定的那个页面和后台登录之后可以正常看到结果