我想保存我的网页地址的变量,但我不断收到的捕获数据从网址
Cannot implicitly convert type 'System.Collections.Specialized.NameValueCollection' to 'string'
一个错误,这是我的语法
protected void Page_Load(object sender, EventArgs e)
{
GetKeyInfo();
}
protected void GetKeyInfo()
{
//The below line is the problem line
string fulladdress = HttpContext.Current.Request.Url.Query;
Response.Write(fulladdress);
string parsed = System.Web.HttpUtility.ParseQueryString(fulladdress);
}
编辑
这是我在试图运行这个地址时显示的地址 http://www.internaltesting.com/PassingDataTest/default.aspx?Information=https://XXX.XXX.X.XXX/all?token=1&cid=1832&employeeid=16432
这是给
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 29: string fulladdress = HttpContext.Current.Request.Url.Query;
Line 30: Response.Write(fulladdress);
Line 31: var parsed = System.Web.HttpUtility.ParseQueryString(fulladdress);
Line 32: string token = parsed["token"];
Line 33: string employeeid = parsed["employeeid"];
编辑
完整的错误这是从web.config中的行,你是后
<compilation debug="true"> <assemblies> <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </assemblies> </compilation>
错误是告诉你问题是什么..你试图将一个列表分配给一个字符串如果你将字符串改为'var parsed',它会将你的代码编译或更改为'NameValueCollection parsed = System.Web.Http Utility.ParseQueryString(“myAddress”);'并添加到类的顶部使用以下'使用System.Collections.Specialized;'谷歌工作在你的脖子上..?看看msdn文档-https://msdn.microsoft.com/en-us/library/ms150046(v = vs.110).aspx –
MethodMan
@MethodMan - var也会抛出一个错误 –
不,它不会。我测试过它和它编译..请粘贴一个示例是什么fulladdress是当你调试代码.. – MethodMan