在webfrom有这段代码,页面Load事件public partial class Default : System.Web.UI.Page
{
protected string avatarFlashParam;
protected string EncodeLocalhost;
protected string Localhost;
protected string uid;
protected void Page_Load(object sender, EventArgs e)
{
int port = HttpContext.Current.Request.Url.Port;
string ApplicationPath = HttpContext.Current.Request.ApplicationPath != "/" ? HttpContext.Current.Request.ApplicationPath : string.Empty;
uid = "1";
Localhost = string.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Host,
(port == 80 || port == 0) ? "" : ":" + port,
ApplicationPath);
EncodeLocalhost = HttpUtility.UrlEncode(Localhost);
avatarFlashParam = string.Format("{0}/images/common/camera.swf?nt=1&inajax=1&appid=1&input={1}&ucapi={2}/Ajax.ashx", Localhost, uid, EncodeLocalhost);
}
}现在转成MVC方式,放在ActionController里public ActionResult Index()
{
protected string avatarFlashParam;
protected string EncodeLocalhost;
protected string Localhost;
protected string uid;
protected void Page_Load(object sender, EventArgs e)
{
int port = HttpContext.Current.Request.Url.Port;
string ApplicationPath = HttpContext.Current.Request.ApplicationPath != "/" ? HttpContext.Current.Request.ApplicationPath : string.Empty;
uid = "1";
Localhost = string.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Host,
(port == 80 || port == 0) ? "" : ":" + port,
ApplicationPath);
EncodeLocalhost = HttpUtility.UrlEncode(Localhost);
avatarFlashParam = string.Format("{0}/images/common/camera.swf?nt=1&inajax=1&appid=1&input={1}&ucapi={2}/Ajax.ashx", Localhost, uid, EncodeLocalhost);
}
}这个Controller里HttpContext.Current.Request.Url.Port等等都报错了,
该怎么该才能得到webfrom方式的HttpContext里的信息呢?
{
protected string avatarFlashParam;
protected string EncodeLocalhost;
protected string Localhost;
protected string uid;
protected void Page_Load(object sender, EventArgs e)
{
int port = HttpContext.Current.Request.Url.Port;
string ApplicationPath = HttpContext.Current.Request.ApplicationPath != "/" ? HttpContext.Current.Request.ApplicationPath : string.Empty;
uid = "1";
Localhost = string.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Host,
(port == 80 || port == 0) ? "" : ":" + port,
ApplicationPath);
EncodeLocalhost = HttpUtility.UrlEncode(Localhost);
avatarFlashParam = string.Format("{0}/images/common/camera.swf?nt=1&inajax=1&appid=1&input={1}&ucapi={2}/Ajax.ashx", Localhost, uid, EncodeLocalhost);
}
}现在转成MVC方式,放在ActionController里public ActionResult Index()
{
protected string avatarFlashParam;
protected string EncodeLocalhost;
protected string Localhost;
protected string uid;
protected void Page_Load(object sender, EventArgs e)
{
int port = HttpContext.Current.Request.Url.Port;
string ApplicationPath = HttpContext.Current.Request.ApplicationPath != "/" ? HttpContext.Current.Request.ApplicationPath : string.Empty;
uid = "1";
Localhost = string.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Host,
(port == 80 || port == 0) ? "" : ":" + port,
ApplicationPath);
EncodeLocalhost = HttpUtility.UrlEncode(Localhost);
avatarFlashParam = string.Format("{0}/images/common/camera.swf?nt=1&inajax=1&appid=1&input={1}&ucapi={2}/Ajax.ashx", Localhost, uid, EncodeLocalhost);
}
}这个Controller里HttpContext.Current.Request.Url.Port等等都报错了,
该怎么该才能得到webfrom方式的HttpContext里的信息呢?
解决方案 »
- .NET 关于前台验证和后台验证的纠结
- 用户 'UDUU-290SWIED\sentang' 登录失败。急
- ajax的问题
- 借个人气,问问,VS2008 SP1怎么删除备份?
- 关于.NET的小问题 谢谢大家
- ASP.NET中鼠标移过的时候显示不同的内容(在一个网站中需要用这种技术)
- a 标签点击去掉粗体
- 20分 (高手进来)服务器问题 幕白兄 等高手
- 我的一个asp.net程序放到服务器,用access做数据库的,但是,在localhost测试全通过 ,但是在服务器上的时候,出错误的。。。。。
- 如此使用SQL到数据库有错吗,为什么不好使呀!请高手指教
- 我在调试的时候出了问题,大家帮忙看看,谢谢了!
- 如何在64位机上运行ajaxpro.2.dll,急用。
方法中嵌套方法?
sorry,直接拷下来了。
public ActionResult Index()
{
protected string avatarFlashParam;
protected string EncodeLocalhost;
protected string Localhost;
protected string uid;
int port = HttpContext.Current.Request.Url.Port;
string ApplicationPath = HttpContext.Current.Request.ApplicationPath != "/" ? HttpContext.Current.Request.ApplicationPath : string.Empty;
uid = "1";
Localhost = string.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Host,
(port == 80 || port == 0) ? "" : ":" + port,
ApplicationPath);
EncodeLocalhost = HttpUtility.UrlEncode(Localhost);
avatarFlashParam = string.Format("{0}/images/common/camera.swf?nt=1&inajax=1&appid=1&input={1}&ucapi={2}/Ajax.ashx", Localhost, uid, EncodeLocalhost); }
我就是要在Controller里得到HttpContext里的信息,然后传给页面ViewData[avatarFlashParam]那四个参数