Hello, when you start a web application on ASP.NET MVC, the default Default.aspx page loads, it does not display png pictures, and an error occurs
: 33120 / Views / Default? ReturnUrl =% 2fScripts% 2fjquery-3.1.0.js: 2 Uncaught SyntaxError: Unexpected token <
and in the address bar is displayed
localhost: 33120 / Views / Default? ReturnUrl =% 2fViews% 2fDefault.aspx
at the same time, the line number in the error apparently refers to this line in Default.aspx (since as you move this line, the number in the error changes accordingly.)
<!DOCTYPE html>
After searching for similar errors on the Internet, I found that the problem could be related to the use of System.Web.Routing. The application has a general structure.
- Views
- Default.aspx
- Content
- bootstrap.min.css
- Resources
- Images
- logo.png
- Images
- Scripts
- jquery-3.1.0.js
- Global.asax.cs
Therefore, in the RegisterRoutes method of the class Global.asax.cs added
routes.RouteExistingFiles = false; routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Scripts" }); routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Content" }); routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Resources" });
When calling a picture in Default.aspx
<img class="img-responsive center-block" src=" <% ResolveUrl("~/Resources/Images/logo.png");%>" alt="Image is lost."/>
But nothing has changed and did not help. Help solve this problem, please.
PS Contents default.aspx (without the first default line)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head id="Head1" runat="server"> <title>Project</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> <link href="../Content/bootstrap.min.css" rel="stylesheet"/> </head> <body> <div class=".container-fluid" style="background: linear-gradient(45deg, #EECFBA, #C5DDE8); width: 100%"> <div class="row" style="padding-top: 81px"> <div class="col-md-4 col-xs-4 col-sm-4"></div> <div class="col-md-1 col-xs-1 col-sm-4"> <!--Logo picture----> <img class="img-responsive center-block" src=" <% ResolveUrl("~/Resources/Images/logo.png");%>" alt="Image is lost."/> </div> <div class="col-md-1 col-xs-1 col-sm-1"> <p style="color: black; font-family: fantasy; font-size: 36px;"> <strong>P</strong>r<strong style="color: gold">oject</strong> </p> </div> <div class="col-md-1 col-xs-1 col-sm-1"></div> <div class="col-md-1 col-xs-1 col-sm-1"></div> <div class="col-md-4 col-xs-4 col-sm-4"></div> </div> <!--Login form--> <div class="row" style="padding-bottom: 81px; padding-top: 36px;"> <div class="col-md-4 col-xs-4 col-sm-4"></div> <div class="col-md-4 col-xs-4 col-sm-4" style="background: silver"> <form id="Form1" role="form" runat="server"> <!--User name --> <div class="form-group"> <label style="font-size: 20px; padding-top: 15px;">Username</label> <asp:TextBox ID="UserEmail" runat="server" CssClass="form-control"/> <asp:CustomValidator ID="CustomValidator_UserEmail" runat="server" OnServerValidate="CustomValidator_UserEmail_OnServerValidate"/> </div> <!--Password--> <div class="form-group"> <label style="font-size: 20px; padding-top: 15px;">Password</label> <asp:TextBox ID="UserPass" runat="server" CssClass="form-control" TextMode="Password"/> <asp:CustomValidator ID="CustomValidator_UserPass" runat="server" OnServerValidate="CustomValidator_UserPass_OnServerValidate"/> </div> <!--Remeber pass--> <div class="form-group"> <div class="checkbox"> <label> <asp:CheckBox ID="cbRememberPassword" runat="server" CssClass="checkbox"/> Forget me? </label> <asp:HyperLink ID="hpForgetPass" runat="server" Text="Lost your password?"/> </div> </div> <!--Authentication failed--> <div class="form-group" style="padding-top: 5px"> <asp:Label ID="lblMessageIncredential" runat="server" ForeColor="red"/> </div> <!--Login button--> <div class="form-group" style="padding-top: 5px"> <asp:Button ID="btnLogin" runat="server" CssClass="btn btn-primary center-block" OnClick="btnLogin_OnClick" Text="Log On"/> </div> </form> </div> </div> </div> </body> </html>
Part of the code from Default.aspx.cs
protected void btnLogin_OnClick(object sender, EventArgs e) { CustomValidator_UserEmail.Validate(); CustomValidator_UserPass.Validate(); if (!Page.IsValid) { return; } var login = ClientServiceFactoryClass.CompanyService.AuthenticateUser(UserEmail.Text, UserPass.Text); if (login != -1) { FormsAuthentication.RedirectFromLoginPage(UserEmail.Text, cbRememberPassword.Checked); Response.Redirect(login == 1 ? Routes.HOME_PAGE_OF_ADMIN : Routes.PAGE_OF_COMPANY_SHORT); } else { lblMessageIncredential.Text = Dictionary.INVALID_LOGIN; UserEmail.Text = string.Empty; UserPass.Text = string.Empty; } }
Where, for example, public const string HOME_PAGE_OF_ADMIN =@"HomeAdmin.aspx";
Content of the RegisterRoutes method
routes.RouteExistingFiles = false; routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Scripts" }); routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Content" }); routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Resources" }); routes.EnableFriendlyUrls();
When prompted, localhost: 33120 / displays in the address bar localhost:33120/Views/Default?ReturnUrl=%2f
for localhost: 33120 / Default this address remains, but errors still occur.
contents of the web.config section of the system.web and system.webServer
<system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="UrlRoutingModule" /> </modules> <directoryBrowse enabled="true" /> </system.webServer> <system.web> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> </compilation> <httpRuntime targetFramework="4.5" /> <pages> <namespaces> <add namespace="System.Web.Optimization" /> </namespaces> <controls> <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" /> </controls> </pages> <profile defaultProvider="DefaultProfileProvider"> <providers> <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> </providers> </profile> <membership defaultProvider="DefaultMembershipProvider"> <providers> <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <roleManager defaultProvider="DefaultRoleProvider"> <providers> <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> </providers> </roleManager> <sessionState mode="InProc" customProvider="DefaultSessionProvider"> <providers> <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /> </providers> </sessionState> <authentication mode="Forms"> <forms loginUrl="Views/Default" name=".ASPXFORMSAUTH" /> </authentication> <authorization> <deny users="?" /> </authorization> </system.web>