Heres My scenario. I have a web site that when the user registers they get a page telling them that a confirmation e-mail will be arriving shortly in thei mailbox in this email theres a link that points to the axtivate.aspx page with a userId QueryString
This Querystring holds the Guid of the user. This is whats used to pull their account on this page. The e-mail works fine but when I click the link I get the following 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: CS0118: 'System.Web.HttpRequest.QueryString' is a 'property' but is used like a 'method'
Source Error:
Line 14: protected void Page_Load(object sender, EventArgs e)
Line 15: {
Line 16: string userId = Request.QueryString("userId");
Line 17: Guid oGuid = new Guid(userId);
Line 18: MembershipUser oUser = Membership.GetUser(oGuid);
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class activate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string userId = Request.QueryString("userId");
Guid oGuid = new Guid(userId);
MembershipUser oUser = Membership.GetUser(oGuid);
if (!((oUser == null)) && oUser.IsApproved == false)
{
oUser.IsApproved = true;
Roles.AddUserToRole(oUser.ToString(), "Member");
Membership.UpdateUser(oUser);
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(oUser.UserName, false);
}
}
}
I Highlighted the line in question in Red. Anyone have any ideas why I'm getting this error?
Deano252
Member
24 Points
9 Posts
QueryString is a Property but used like a method error when Activate.aspx is loded
Mar 13, 2007 12:55 PM|LINK
Hi,
Heres My scenario. I have a web site that when the user registers they get a page telling them that a confirmation e-mail will be arriving shortly in thei mailbox in this email theres a link that points to the axtivate.aspx page with a userId QueryString This Querystring holds the Guid of the user. This is whats used to pull their account on this page. The e-mail works fine but when I click the link I get the following 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: CS0118: 'System.Web.HttpRequest.QueryString' is a 'property' but is used like a 'method'
Source Error:
Source File: \\shared.hosting.local\nfs\cust\3\03\03\730303\web\activate.aspx.cs Line: 16
and this is my Activate.aspx.cs code
I Highlighted the line in question in Red. Anyone have any ideas why I'm getting this error?SomeNewKid
All-Star
45894 Points
8027 Posts
Re: QueryString is a Property but used like a method error when Activate.aspx is loded
Mar 13, 2007 01:02 PM|LINK
In C#, you need to use square brackets when accessing properties such as QueryString.
Change:
string userId = Request.QueryString("userId");
to:
string userId = Request.QueryString["userId"];
Please note that your code would fail if the query string did not include a userId value. To make this code better, you might do something like this:
Object userIDinQueryString = Request.QueryString["userId"];
if (userIDinQueryString != null && userIDinQueryString is String)
{
String userID = (String)userIDinQueryString;
if (String.IsNullOrEmpty(userID) == false)
{
Guid oGuid = new Guid(userId);
MembershipUser oUser = Membership.GetUser(oGuid);
// and the rest
}
}
I hope this helps.
Haissam
All-Star
37421 Points
5632 Posts
Re: QueryString is a Property but used like a method error when Activate.aspx is loded
Mar 13, 2007 01:04 PM|LINK
Try
string userId = Request.QueryString["userId"];
HC
MCAD.NET
| Blog |
fahiemulleh
Member
232 Points
91 Posts
Re: QueryString is a Property but used like a method error when Activate.aspx is loded
Mar 13, 2007 01:50 PM|LINK