Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net url中id为的页面-是否应在页面加载中检查它是否为整数?_Asp.net - Fatal编程技术网

Asp.net url中id为的页面-是否应在页面加载中检查它是否为整数?

Asp.net url中id为的页面-是否应在页面加载中检查它是否为整数?,asp.net,Asp.net,如果我有自定义胶片的详细信息页面(数据库中的主键胶片是整数),例如:-我应该在页面加载事件中验证filmId是否为数字??因为有人可以修改链接,所以设置filmId=例如“abc”,然后呢?在将其用于假定为整数值的操作之前,您可以检查它是否是有效的整数 您可以编写这样的扩展方法 public static bool IsNumeric(this string input) { int temp; return int.TryParse(input, out temp); } strin

如果我有自定义胶片的详细信息页面(数据库中的主键胶片是整数),例如:-我应该在页面加载事件中验证filmId是否为数字??因为有人可以修改链接,所以设置filmId=例如“abc”,然后呢?

在将其用于假定为整数值的操作之前,您可以检查它是否是有效的整数

您可以编写这样的扩展方法

public static bool IsNumeric(this string input)
{
  int temp;
  return int.TryParse(input, out temp);
}
string strFilmId=Request.QueryString["filmId"];
if(strFilmId.IsNumeric())
{
  int filmId=Convert.ToInt32(strFilmId);
  //use the integer variable now
}
else
{
  // show the message to user that the url is not valid.
}
然后像这样在页面加载中使用它

public static bool IsNumeric(this string input)
{
  int temp;
  return int.TryParse(input, out temp);
}
string strFilmId=Request.QueryString["filmId"];
if(strFilmId.IsNumeric())
{
  int filmId=Convert.ToInt32(strFilmId);
  //use the integer variable now
}
else
{
  // show the message to user that the url is not valid.
}

在将其用于假定为整数值的操作之前,可以检查它是否为有效整数

您可以编写这样的扩展方法

public static bool IsNumeric(this string input)
{
  int temp;
  return int.TryParse(input, out temp);
}
string strFilmId=Request.QueryString["filmId"];
if(strFilmId.IsNumeric())
{
  int filmId=Convert.ToInt32(strFilmId);
  //use the integer variable now
}
else
{
  // show the message to user that the url is not valid.
}
然后像这样在页面加载中使用它

public static bool IsNumeric(this string input)
{
  int temp;
  return int.TryParse(input, out temp);
}
string strFilmId=Request.QueryString["filmId"];
if(strFilmId.IsNumeric())
{
  int filmId=Convert.ToInt32(strFilmId);
  //use the integer variable now
}
else
{
  // show the message to user that the url is not valid.
}

看到这篇文章,它会回答你的问题。干杯。看到这篇文章,它会回答你的问题干杯。