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
Avatar of Patrick Bogers
Patrick Bogers
Flag of Netherlands image

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.
Avatar of Steve7423
Steve7423
Flag of Canada image

ASKER

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 ?
Avatar of kaufmed
kaufmed
Flag of United States of America image

What does this line:

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

Open in new window


...look like in the client-side source code?
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)
Avatar of Steve7423
Steve7423
Flag of Canada image

ASKER

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
Avatar of Steve7423
Steve7423
Flag of Canada image

ASKER

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)
Avatar of Steve7423
Steve7423
Flag of Canada image

ASKER

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
Avatar of Steve7423
Steve7423
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of kaufmed
kaufmed
Flag of United States of America image

If you solved the issue yourself, then you would typically select your own comment as the solution.
Avatar of Steve7423
Steve7423
Flag of Canada image

ASKER

kaufmed: as per your suggestion, Thank you all for helping me, much appreciated.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo