Avatar of Steve7423
Steve7423Flag for Canada asked on

ASP.net MVC 3 Alert messages cause error message on page. (Unable to display alerts)

I have a page that first checks to see if the message property contains a value, if it does then display it.  The problem is that when I publish the site to the web server, the page displays an error; see attached.  If I comment out the alert(msg) the page displays without an error.  If I uncomment, it errors out.  Not knowing enough about this I'm not sure what to consider as the problem.  i suspect it's iis related or permissions, but not sure.

<script type="text/javascript">
    $(document).ready(function () {

        var msg = '@ViewData["Message"]';
            if (msg != "")
            alert(msg);  //problem line
    });

</script>
EE-Alert-Err.bmp
ASP.NET

Avatar of undefined
Last Comment
Steve7423

8/22/2022 - Mon
Patrick Bogers

Hi

This can mean many things.

What applicationpool(user) is running the app?
Does the webserver uses the same framework like .NET4,5 as on your developing machine?
Can you try using <customErrors mode="Off"/> between the <system.web> tags?

Do you see an error in the logfiles for this website?

It is a lot but most of the time not to difficult.
ASKER
Steve7423

1 applicationpool, I might need a hand with this, not sure what you're speaking of.
2 yes I installed frameworks 4 and MVC 3
3 it was set to remote only, I changed it to off, published again, opened the site but it still displays the error.
4 not sure where to look for the log files, ..some direction ?
kaufmed

What does this line:

var msg = '@ViewData["Message"]';

Open in new window


...look like in the client-side source code?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Patrick Bogers

Ok app pool is important.
In IIS select your website and click 'basic settings' on the right.
This will display your application pool, now in IIS (left on top) go to application pools and select properties for the app-pool you just found.
I expect to find a .NET 2.0 default apppool which doesnt work if your app is build on .NET4

(i am assuming you use IIS 7 or higher)
ASKER
Steve7423

kaufmed: here's the line from the controller which populates the message of viewbag

if (Convert.ToInt32(DAL.Get_CurrentUsersProjectNo()) > 0)
            {
                ViewData["Message"] = "";
            }
            else
            {
                //err name
                string err_Name = "missing_project_number";
                Errors err_Display = new Errors();

                string errModel = err_Display.Get_Error_Display_Desc(err_Name);

                //Response.Redirect("Error.aspx");
                ViewData["Message"] = errModel;

            }


Patricksr1972:  here's the apppool settings, see attached.

the app pool was set to defaultapppool, I then changed it to .net 4.0, in the process of re-running it, stand by.
App-Pool.bmp
ASKER
Steve7423

K, found the event viewer.  This is what it says:

3005
                  An unhandled exception has occurred.


IIS APPPOOL\DefaultAppPool
                  HttpException
                  A potentially dangerous Request.Path value was detected from the client (<). at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)




Changing the app pool setting I still get the error.

IIS APPPOOL\ASP.NET v4.0
                  HttpException
                  A potentially dangerous Request.Path value was detected from the client (<). at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Steve7423

I set the validaterequest - false in the config, then took it out and now I'm getting the error on my dev machine.
ASKER CERTIFIED SOLUTION
Steve7423

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
kaufmed

If you solved the issue yourself, then you would typically select your own comment as the solution.
ASKER
Steve7423

kaufmed: as per your suggestion, Thank you all for helping me, much appreciated.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes