Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:58:27+00:00 2026-06-13T19:58:27+00:00

Working on my first Web Pages project using C# and Webmatrix. So for thing

  • 0

Working on my first Web Pages project using C# and Webmatrix. So for thing have been going pretty well but have now run into an issue that has me stumped.
What I am doing is posting a form to this page which contains a message and I am then saving the message to the DB (and will later also get the email part going).

I’ve posted the code below, it’s actually longer than need be to illustrate the problem but thought I’d post it all nonetheless. WebMatrix was already highlighting an issue at hand before I tried running it when I saw that the penultimate closing curly brackets was highlighted yellow. When running the code (and the post values are all OK) I get the error “CS1513: } expected”. I initially thought I had by mistake added an extra closing curly bracket, but after checking and double checking and then slowly rebuilding up the code line by line to identify after which line it started going wrong, I have now come to the conclusion that without any of the nested “if” and “foreach” statements within the “if(IsPost && WebSecurity.IsAuthenticated)” “if” statement that it then “works” (although obviously not with the desired logic).

I’ve checked around and I’ve found plenty of C# code examples where this is done. Any help, pointers or anything else much appreciated.

Q

@{
if(IsPost && WebSecurity.IsAuthenticated){
    var fromEmail = WebSecurity.CurrentUserName;
    var fromUserId = @WebSecurity.CurrentUserId;
    var message = Request["message"];
    var uid = Request["uid"];
    bool multiSend = false;
    var db = Database.Open("Tennegize");

    var skillLevel = 0;
    if(Request["multi"]=="1"){
        multiSend = true;
    }

    //Save to message to BD
    var insertQuery = "INSERT INTO Messages (UserEmail, UserId, Message) VALUES (@0, @1, @2)";
    db.Execute(insertQuery, fromEmail, fromUserId, message);
    decimal messageId = db.GetLastInsertId();

    if(multiSend){
         //Get email address' from all recipients
        var sql2 = "SELECT Email FROM UserProfile WHERE SkillLevel = @0";
        var data2 = db.Query(sql, skillLevel);
        var totalRecipents = data2.Count();
        //Log all recipients who will recieve this notification
        foreach(var recipient in data2){
            insertQuery = "INSERT INTO Message_Recipients (UserId, UserEmail, MessageId) VALUES (@0, @1, @2)";
            db.Execute(insertQuery, uid, data.Email, messageId); 
        }

    }else{
        // Get to recipients email address
        var sql = "SELECT Email FROM UserProfile WHERE UserId = @0";
        var data = db.QuerySingle(sql, uid);
        //Log the recipient of this norification
        insertQuery = "INSERT INTO Message_Recipients (UserId, UserEmail, MessageId) VALUES (@0, @1, @2)";
        db.Execute(insertQuery, uid, data.Email, messageId);

    }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:58:28+00:00Added an answer on June 13, 2026 at 7:58 pm

    My guess is that the line var fromUserId = @WebSecurity.CurrentUserId; is causing the problem. Remove the @ before WebSecurity.CurrentUserId.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my first ever ASP.Net project, and I seem to have been
There are multiple pages on my web-project working with exactly same JS functions. I
I am working on a web application project in ASP.Net and I have two
I am working on my first web project and I need help adding IF
I am working with two different web sites in asp.net. In the first project
I'm attempting to get my first ASP.NET web page working on windows using Mono
I'm working on my first very complex JQuery based application. A single web page
I am working on a MVC3 code first web application and after I showed
I'm working on a simple webservice in django. This is my first web app
I am new to wpf and i am working on first application i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.