Asp.net url中id为的页面-是否应在页面加载中检查它是否为整数?
如果我有自定义胶片的详细信息页面(数据库中的主键胶片是整数),例如:-我应该在页面加载事件中验证filmId是否为数字??因为有人可以修改链接,所以设置filmId=例如“abc”,然后呢?在将其用于假定为整数值的操作之前,您可以检查它是否是有效的整数 您可以编写这样的扩展方法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
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.
}
看到这篇文章,它会回答你的问题。干杯。看到这篇文章,它会回答你的问题干杯。